0
次のコードは、ラップトップのVisual Studioから実行すると動作します。 Windowsの2016年のサーバ私は500エラーと例外(.NET Frameworkの4.7)を得る上でIISに展開するときしかし:ObjectContentをHttpContentにキャストできません
ExceptionMessage: "Error getting value from 'Content' on 'System.Net.Http.HttpResponseMessage'." ExceptionType : "Newtonsoft.Json.JsonSerializationException" InnerException ExceptionMessage: "Unable to cast object of type 'System.Net.Http.ObjectContent' to type 'System.Net.Http.HttpContent'." ExceptionType : "System.InvalidCastException"
public HttpResponseMessage Get()
{
// Entities is the Entity Framework context
// Sessions is a proprietary table and has nothing to do with ASP.NET sessions
var content = new Entities().Sessions
.AsEnumerable()
.Select(t =>
{
return new
{
t.Id,
t.SessionId,
t.StartTime,
t.EndTime
};
});
return new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new ObjectContent(typeof(IEnumerable), content, new JsonMediaTypeFormatter())
};
}