Method to prevent web caching throwing exception ASP.NET?
I am trying to stop the caching of web pages using the following snippets in the ASP.NET however its not working and showing following error to me,
Response.CacheControl = "no-store";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;
Following is the exception i am getting,
Exception Details: System.ArgumentException: Property value for CacheControl is not valid. 开发者_JAVA技巧 Value=no-store.
Reading at the MSDN document it looks "no-store" is valid value but still there is this error. Can some one please help on this.
Thanks,
Try this:
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
That help page looks like it is an asp reference page, not an asp.net reference page.
The page you want is http://msdn.microsoft.com/en-us/library/system.web.httpresponse.cachecontrol.aspx which suggests that the valid values are those that match the httpcacheability enum. See the following page:
http://msdn.microsoft.com/en-us/library/system.web.httpcacheability.aspx
In particular the value you want is, I would guess, NoCache. Though you'd have to read the help to make sure that is definitely the one you want.
精彩评论