当前位置: 代码迷 >> ASP.NET >> WebService中,怎么修改HttpResponse.StatusCode
  详细解决方案

WebService中,怎么修改HttpResponse.StatusCode

热度:2559   发布时间:2013-02-25 00:00:00.0
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宿主来控制的。
------解决方案--------------------------------------------------------
你修改了也没用,这是浏览器负责的
  相关解决方案