开发者

How to send Cache-Control: no-cache in HTTP Response header?

开发者 https://www.devze.com 2023-03-31 22:31 出处:网络
Net 4 and C#. I would need set send to Browser Cache-Control (Cache-Control: no开发者_开发知识库-cache) in the HTTP Response header for a Web Form page.

Net 4 and C#.

I would need set send to Browser Cache-Control (Cache-Control: no开发者_开发知识库-cache) in the HTTP Response header for a Web Form page.

Any idea how to do it?

Thanks for your time.


Try this:

Response.AppendHeader("Cache-Control", "no-cache");

However, you should know that this header alone won't give you a reliable cross-browser way to prevent caching. See this answer for more accurate solution: Making sure a web page is not cached, across all browsers


In MVC you can set it in the Controller class, so the View not use cache;

public ActionResult User()
{
    Response.CacheControl = "no-cache";
    return View();
}


For dotnet core:

Response.Headers.Append("Cache-Control", "no-cache, no-store, must-revalidate");
0

精彩评论

暂无评论...
验证码 换一张
取 消