8

I have a generic error page, that any handled error will redirect to. I have an admin page that when the user invokes an error, and the user is brought to the error page, hitting the back button from the error page cause the admin page to load improperly.

So what I need, is a way to reload the admin page when I come from the error page. I have tried setting no cache and such on the admin page, and checking for a postback, but nothing works. Setting no cache seems to do nothing, and any javascript on the admin page's document.ready function does not get called either. Is there any other ways to get this to happen?

EDIT:

I should also mention that I have noticed that a table is missing 2 cells I recently added. This makes me believe that there is a old state of the page being cached somewhere, although clearing the browser cache and restarting my server do not help at all.

Edit2:

Also, setting window.onload() gets nuked when I come back to the admin page

Keerigan
  • 1,182
  • 1
  • 9
  • 17

2 Answers2

2

You should be able to take care of that by overriding OnInit with this code:

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

        //EDIT: Set the value to FALSE
        Response.Cache.SetAllowResponseInBrowserHistory(false);

        base.OnInit(e);
    }
}

See this question for more details: Back button refresh page

EDIT

For clearing the cache, check this out:
Manually clear ASP.NET server cache for a single application/web site?

Community
  • 1
  • 1
James Johnson
  • 45,496
  • 8
  • 73
  • 110
  • I've tried doing this, but nothing. It makes me thing that there is an old state of my page being cached somewhere, but clearing the cache in the browser and restarting my server do nothing. – Keerigan Apr 02 '12 at 16:04
  • I added an extra line to `OnInit` for you to try out. I also added a JavaScript solution, but it's kind of a hack. – James Johnson Apr 02 '12 at 16:15
  • that new line still doesn't help. and just doing the window.onload puts the initial load into a loop – Keerigan Apr 02 '12 at 16:31
  • Lol, I say it thought "This doesn't look right", but I thought I would try it anyway – Keerigan Apr 02 '12 at 16:36
  • Try changing it to `SetAllowResponseInBrowserHistory(false)`. When you test these changes make sure you've flushed everything, restart the application, and clear the cache completely. – James Johnson Apr 02 '12 at 16:40
  • Just tried that, still nothing. Maybe I am not clearing my cache properly? How do I completely clear the cache? – Keerigan Apr 02 '12 at 16:45
  • Is it running on Cassini or IIS? – James Johnson Apr 02 '12 at 16:48
  • I think doing that would mess up some other people's work. I would like to solve this without doing that – Keerigan Apr 02 '12 at 17:02
  • Are you trying to do this on a live environment with active users? – James Johnson Apr 02 '12 at 17:04
  • As far as I know IIS is running, but the server that gets created from VS2010 is on its own, so no one can actually be on it but me – Keerigan Apr 02 '12 at 17:06
  • So you're using the built-in hosting environment in Visual Studio? That means you're using Cassini. – James Johnson Apr 02 '12 at 17:09
  • Well then, I did not know that. Sorry. I'm running Cassini then. Anything you know will work on there? Now also, although my issue is happing here, this will be deployed to an IIS server...I think. In either case, can you still help me with the issue on Cassini? – Keerigan Apr 02 '12 at 17:14
0

So it turns out this is just an IE9 issue. My onload method was just never getting called. Works fine in the other browsers.

The fix I had to make in order get this to work in IE9 as well was to append a query string to the page, so that when I come back to the page, IE9 will go back to the browser incise the query string has changed or needs to be re-evaluated.

Thanks to both of you guys, or help helped me find the issue.

Keerigan
  • 1,182
  • 1
  • 9
  • 17