Saturday 29 July 2017

Removing Browser Cache using this code



Removing Browser Cache using this code


We can also achieve this by disabling browser caching in code behind write the following lines of code in Page_Init event or Page_Load event and don’t forgot to add namespace 
using System.Web; becauseHttpCacheability related to that namespace.


protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();

}

We need to place this code in a page wherever we need to disable browser back button. If we use above caching method to disable browser back button that will display webpage expired message like this.

No comments:

Post a Comment