Visual Studio ASP.NET development server keeps returning old pages
Asked Answered
C

1

6

I have created an ASP.NET 4 based website. At first I ran the default site as it was generated by Visual Studio ASP.NET 4 Internet Application template. I just hit the Debug button, and IE was launched, it connected to http://localhost:1341/ and loaded the default welcome page of my website. Everything seemed fine, so I started to redesign the Index.cshtml.

After redesigning, I launched the website again. And while navigating, I noticed that if I click browser's Back button, I get the cached old version of the first page and I have to hit Refresh in the browser to get the new one.

So I added

    <meta http-equiv="PRAGMA" content="NO-CACHE">

and

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        // prevent caching
        HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
        HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoStore();
    }

to my website.

Then I cleared the IE cache using IE Options. I also cleaned my Local\Temp folder.

But still I got Result 304 in the IE developer tools Network tab when hitting Back button in the browser.

The only way to get the new redesigned page is to use Cache->Always refresh from server. I could do that for development purposes, but it is just messing my mind up - where does it get that very old page from always when I hit Back?

When debugging, in Visual Studio there appears a new tree item in the Solution Explorer. This new item is called Script documents. Under it, there is a Windows Internet Explorer item which contains localhost item ... and when I open it - yeah, that's the old page which is coming to IE when I hit Back button! Where does Visual Studio (or ASP.NET Dev server) store that "localhost" page?

How do I get rid of that stuck page and stop IE (or maybe also the ASP.Dev server) from caching my localhost/ front page? How do I delete that old page for good?

I hope, the new page won't be cached the same way, because I added to it...

Caliper answered 5/9, 2012 at 16:11 Comment(4)
This is not a code issue; it's an IE issue and you already know the work around based on your post.Railey
But where does it get that old page from and why it appears even in Visual Studio Solution explorer while debugging? I cleaned every place I know (IE cache, Temp folder), but still that first page is cached somewhere else...Caliper
I agree. And I don't think this is a plain IE issue. It's either an issue with Cassini (also cleared the cache but problem still happens), Visual Studio or IE in debug mode. It only happens in "development mode" and only when you use the back button or equivalent. It is the sort of gotcha that will drive any developer nuts (well more nuts). I'd also like to know where this old copy is stored because it will probably help to fix it.Allative
I just want to clarify for those that think this is just a normal caching problem. You create a page version A and run it. Then you change it to version B and run it. You get version B in the browser so this should be the version cached from now on, but when you press back to get back to this page, you get version A. I've found that rebooting the machine fixes the issue. Maybe there is an in memory cache somewhere that we cant' get to, and maybe the URL of the original load is different to that of the back (but how?).Allative
A
0

add

<meta http-equiv="CACHE-CONTROL" content="NO-CACHE"/>
<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT">
Angularity answered 20/9, 2012 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.