Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do Response.Cache.SetCacheability and Response.Cache.SetAllowResponseInBrowserHistory mean?

Tags:

asp.net

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetAllowResponseInBrowserHistory(false);

While searching for authentication, I found the above two lines written. What do they mean?

like image 937
Shalni Avatar asked Oct 04 '10 11:10

Shalni


3 Answers

What I found out by a hard way and a day of the research that having Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache)

in Global.asax.cs file:

protected void Application_PreSendRequestHeaders(Object sender, EventArgs e)
{
    Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
}

helps handling refreshing pop up window with a new data in IE browser.

Setting that, invokes a controller second time the pop up window is opened and refreshes the data inside from the server.

Hope it will help someone.

like image 74
gene Avatar answered Oct 16 '22 13:10

gene


HttpCachePolicy.SetCacheability Method

NoCache: Sets the Cache-Control: no-cache header. Without a field name, the directive applies to the entire request and a shared (proxy server) cache must force a successful revalidation with the origin Web server before satisfying the request. With a field name, the directive applies only to the named field; the rest of the response may be supplied from a shared cache.

HttpCachePolicy.SetAllowResponseInBrowserHistory Method

When HttpCacheability is set to NoCache or ServerAndNoCache the Expires HTTP header is by default set to -1; this tells the client not to cache responses in the History folder, so that when you use the back/forward buttons the client requests a new version of the response each time.

like image 43
ChrisF Avatar answered Oct 16 '22 13:10

ChrisF


The first one tells the browser not to cache this page (see here), and the second one tells the browser not to include this page in the browse history (see here).

like image 5
Carvellis Avatar answered Oct 16 '22 12:10

Carvellis