Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent caching in Internet Explorer?

I am developing a web application in ASP.NET and on some pages I want to prevent them from caching the data using the following code:

protected override void OnInit(EventArgs e)
{
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetNoStore();
    Response.Cache.SetExpires(DateTime.MinValue);

    base.OnInit(e);
}

This works like it should, but now when the user tries to refresh the page after a postback (e.g. saving the data) the browser informs the user that action will be caused twice if he proceeds and asks you if you want to continue or not. If you cancel this on Chrome or Firefox the page still has its current state - which is exactly what I want, but in IE it is invalidated.

Is there any way to achieve the same behaviour for Internet Explorer?

like image 200
Bautzi89 Avatar asked Nov 27 '25 16:11

Bautzi89


1 Answers

You probably need to take a different approach. Try creating a custom confirmation box to catch/cancel the refresh action:

http://devzone.co.in/show-confirmation-box-page-refresh-page-unload-using-javascript/

Execute function before refresh (although this solution has a comment that says it doesn't work on FireFox).

like image 127
Ian Avatar answered Nov 29 '25 10:11

Ian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!