Manipulating ASP.NET response headers not working

时间:2016-10-20 13:24:16

标签: asp.net http-headers

I want to allow cashing for a specific ajax request. Currently the response does not allow this:

HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
Content-Type: application/json; charset=utf-8
X-SLPROMOTION: DEBUG
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcS2F5WmFuZGVyXERvY3VtZW50c1xWaXN1YWwgU3R1ZGlvIDIwMTVcUHJvamVjdHNcc3BvcnRsb29wXHRvb3R3b29cQWNjb3VudFxJc1RyYWluZXI=?=
X-Powered-By: ASP.NET
X-SDL-VERSION: 1.0
Access-Control-Allow-Origin: *
Date: Thu, 20 Oct 2016 13:18:04 GMT
Content-Length: 51

So I set the headers:

  public JsonResult MyFunction()
        {          
            HttpContext.Response.Headers.Remove("cache-control");
            HttpContext.Response.AppendHeader("cache-control", "public");
...}

but the response still contains:

Cache-Control: private, s-maxage=0

Could this be caused by a global setting or what is the trick here?

1 个答案:

答案 0 :(得分:0)

尝试

HttpContext.Response.Cache.SetCacheability(HttpCacheability.Public);

更多信息here