日期:2014-05-18  浏览次数:20444 次

WebService中,如何修改HttpResponse.StatusCode
WebService方法如下:

  public ExampleModel FindAModel(string _id)
  {
  HttpResponse response = HttpContext.Current.ApplicationInstance.Response;
  response.StatusCode = (int)HttpStatusCode.Unauthorized;
  response.StatusDescription = "this is a test!";
  response.ContentType = "application/json";
  return this.Buffer.FirstOrDefault(p => p.ID.Equals(_id));
  }

通过工具查看http返回信息,始终是200 ok
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 30 Mar 2012 10:07:41 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 34
Cache-Control: private
Content-Type: application/json; charset=utf-8
Connection: Close


请问:我如何才能修改其值呢?

------解决方案--------------------
这个不是程序来控制的,是IIS和ASP.NET宿主来控制的。
------解决方案--------------------
你修改了也没用,这是浏览器负责的