GibboK
GibboK

Reputation: 73998

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

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.

Upvotes: 6

Views: 45456

Answers (3)

Omar M.
Omar M.

Reputation: 341

For dotnet core:

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

Upvotes: 1

Hernaldo Gonzalez
Hernaldo Gonzalez

Reputation: 2056

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

Upvotes: 1

Dyppl
Dyppl

Reputation: 12381

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

Upvotes: 8

Related Questions