【发布时间】:2014-05-12 18:53:55
【问题描述】:
客户端发出GET 请求,这里是 api 响应:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 26
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Set-Cookie: ARRAffinity=636f48abd1e4ad4818a02dc087a9bd0c1be56fb972e821c7c8cf37553bc46cc3;Path=/;Domain=testtest11.azurewebsites.net
Date: Sun, 13 Apr 2014 19:57:08 GMT
Connection: close
我希望响应头不包含
"Cache-Control", "Pragma", "Expires", "Server", "X-AspNet-Version", "设置 Cookie"
换句话说,我希望得到理想的响应。
HTTP/1.1 200 OK
Pragma: no-cache
Content-Length: 26
Content-Type: application/json; charset=utf-8
Date: Sun, 13 Apr 2014 19:57:08 GMT
Connection: close
我该怎么办?
asp.net web api 代码示例:
public class ProductsController : ApiController
{
public HttpResponseMessage GetProduct(string id)
{
HttpResponseMessage respMessage = new HttpResponseMessage();
respMessage.Headers.Clear();
respMessage.Content = new ObjectContent<string[]>(new string[] { "value22", "value2" }, new JsonMediaTypeFormatter());
return respMessage;
}
}
【问题讨论】:
-
你在使用表单认证吗?
-
不,我没有设置 FormsAuthentication。而且我不知道 FormsAuthentication。本项目代码为VS2013 IDE默认Web API4代码。
-
你的意思是你希望它包括缓存?因为您发送的响应没有
-
换句话说,我希望得到理想的响应。 "HTTP/1.1 200 OK Pragma: no-cache Content-Length: 26 Content-Type: application/json; charset=utf-8 Date: Sun, 13 Apr 2014 19:57:08 GMT Connection: close"
标签: c# cookies asp.net-web-api http-headers