[英].Net Core 2.0 replacement for HttpResponseBase
I am porting some code from an old MVC 5 app to a Core 2.0 app. 我将一些代码从旧的MVC 5应用程序移植到Core 2.0应用程序。
The SerializeData method is failing as HttpResponseBase is no longer in Core 2.0 and I can't seem to find a suitable replacement in any of the Core libraries. SerializeData方法失败,因为HttpResponseBase不再在Core 2.0中,我似乎无法在任何Core库中找到合适的替代品。 Resharper not even detecting the proper library to add as a dependency.
Resharper甚至没有检测到要作为依赖项添加的正确库。
private void SerializeData(HttpResponseBase response)
{
if (ErrorMessages.Any())
{
Data = new
{
ErrorMessage = string.Join("\n", ErrorMessages),
ErrorMessages = ErrorMessages.ToArray()
};
response.StatusCode = 400;
}
if (Data == null) return;
response.Write(Data.ToJson());
{
}
}
public static class JsonExtensions
{
public static string ToJson<T>(this T obj, bool includeNull = true)
{
var settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new JsonConverter[] { new StringEnumConverter() },
NullValueHandling = includeNull ? NullValueHandling.Include : NullValueHandling.Ignore
};
return JsonConvert.SerializeObject(obj, settings);
}
}
Reference the following package: 参考以下包:
using Microsoft.AspNetCore.Http.HttpResponse;
And change HttpResponseBase
to HttpResponse
: 并将
HttpResponseBase
更改为HttpResponse
:
private void SerializeData(HttpResponse response)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.