【问题标题】:I want that HttpResponse header do not include Set-Cookie我希望 HttpResponse 标头不包含 Set-Cookie
【发布时间】: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


【解决方案1】:

从这篇文章开始:http://www.strathweb.com/2012/05/output-caching-in-asp-net-web-api/

Web API 不支持盒子中的输出缓存,filip 为它做了一个很好的库。

【讨论】:

    猜你喜欢
    • 2019-08-01
    • 2020-02-14
    • 2011-09-26
    • 1970-01-01
    • 2021-01-08
    • 2017-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多