我正在使用.NET MVC。
当我返回new HttpResult(HttpStatusCode.NoContent);
时,创建的对象的状态代码为= 200:
{ServiceStack.Common.Web.HttpResult}
AllowsPartialResponse: false
ContentType: null
FileInfo: null
Headers: Count = 0
IsPartialRequest: false
Options: Count = 0
RequestContext: null
Response: NoContent
ResponseFilter: {ServiceStack.Common.Web.HttpResponseFilter}
ResponseStream: null
ResponseText: null
Status: 200
StatusCode: OK
StatusDescription: null
Template: null
View: null
呃...什么?
答案 0 :(得分:4)
如果要使用带有HttpStatusCode
如果查看HttpResult的代码,可以看到您调用的构造函数是:
public HttpResult(object response) : this(response, null) {}
您传入的HttpStatusCode
对象实际上被用作响应(任何对象都可以作为响应)。你应该在这里使用另一个构造函数:
public HttpResult(HttpStatusCode statusCode, string statusDescription)
即
new HttpResult(HttpStatusCode.NoContent, "No Content");