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

37,566

Solution 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

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

Solution 3

For dotnet core:

Response.Headers.Append("Cache-Control", "no-cache, no-store, must-revalidate");
Share:
37,566
GibboK
Author by

GibboK

A professional and enthusiastic Senior Front End Developer. Listed as top 2 users by reputation in Czech Republic on Stack Overflow. Latest open source projects Animatelo - Porting to JavaScript Web Animations API of Animate.css (430+ stars on GitHub) Industrial UI - Simple, modular UI Components for Shop Floor Applications Frontend Boilerplate - An opinionated boilerplate which helps you build fast, robust, and adaptable single-page application in React Keyframes Tool - Command line tool which convert CSS Animations to JavaScript objects gibbok.coding📧gmail.com

Updated on July 09, 2022

Comments

  • GibboK
    GibboK almost 2 years

    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.