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

落爺英雄遲暮 提交于 2019-12-23 09:29:25

问题


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.


回答1:


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




回答2:


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();
}



回答3:


For dotnet core:

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


来源:https://stackoverflow.com/questions/7242579/how-to-send-cache-control-no-cache-in-http-response-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!