How do I turn off caching for my entire ASP.NET MVC 3 website?

后端 未结 4 1571
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 03:21

Like the question says, I wanted to know if it\'s possible to turn off caching on all controllers and actions for my entire site. Thanks!

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 03:38

    You should add this method to your Global.asax.cs file

    protected void Application_BeginRequest(object sender, EventArgs e)
            {
                Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
                Response.AddHeader("Pragma", "no-cache"); // HTTP 1.0.
                Response.AddHeader("Expires", "0"); // Proxies.
            }
    

    This disables cache on every request (images, html, js etc.).

提交回复
热议问题