Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have used below code on base page protected override void OnLoad(EventArgs e) and .aspx onload event .but since it fails to set cache-control-no-chae is is setting to as private got get request.please help me how to do this

C#
HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(false);
            HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store");
            HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            HttpContext.Current.Response.Cache.SetNoStore();
            Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
            Response.Cache.SetValidUntilExpires(true);


I have also used this code global.asax on begin request.but again it fails

Guys,please help me how to set it as in cache-control-no-cache.
Posted

1 solution

Hello Rajshree,
I think there is another way to set no-cache for your sites. Here is something that you can try with
From IIS, select the website/virtual directory/folder you want to mark it as no-cache. From there right click and select the HTTP Headers tab. Click Add button in the Custom HTTP Headers section. Add a header named Cache-Control with a value as no-cache. Click ok to apply the changes. You might need to restart the IIS for make the changes work on the site.
 
Share this answer
 
Comments
rajshreelande 16-Oct-14 8:33am    
is it applied to all resources in pages like scripts and Ajax script manager.
NaibedyaKar 16-Oct-14 8:35am    
Yes, it can be applied to all the resources. You can add it at root level or folder level.
rajshreelande 16-Oct-14 9:37am    
i want to set no cache no-store for scriptresource.axd how to do dis?
NaibedyaKar 16-Oct-14 10:01am    
yes, I think you can do that in the same way by adding a new header.
Do you really want to add no-store? Check this http://blogs.atlassian.com/2007/12/cache_control_no_store_considered_harmful/
rajshreelande 17-Oct-14 6:42am    
Hello NaibedyaKar (Mindfire) ,

THANKU VERY MUCH BUT,
I have done setting IIS LEVEL BUT FOR ASPX PAGES CACHE-CONTENT:NO-CACHE,NO-STORE,NO-CACHE,NO-STORE IS SETTING (meanS i dont want DULPICATION)
AND FOR SCRIPTSOURCE.AXD AND WEBSOURCE.AXD IS SETTING AS PUBLC,NO-CACHE,NO-STORE.
I WANT IT AS SIMPLE NO-CACHE,NO-STORE..DO U HAVE ANY IDEA ABOUT DIS.

PLEASE HELP ME.

REGARDS,
RAJSHREE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900