简体   繁体   中英

Asp.Net Force Page_Load when Clicking Back Button On Browser

I have an ASP.NET project that I have created in Visual Studio 2010. So to begin the project, I got the generic "MY ASP.NET APPLICATION" page. I have since removed all that generic content and am building the application based off the needs of the user.

On my default.aspx page, I have a datagrid wrapped in an UpdatePanel . When a user selects a row from the datagrid , I navigate to a new page. Everything is working fine but if the user was to click the back button in the browser, it acts as if it is loading the page from an old cached version because it shows the generic "MY ASP.NET APPLICATION" page again.

I have researched this for awhile and everything says that if you tell the Response not to use the cache, it forces the Page_Load to hit if the user clicks the back button. However, doing this is not working for me. If I were to click the refresh button, or type F5, then my page is reloaded successfully. I am using IE9 and here is what I have tried in the Page_Load of my master page:

        Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
        Response.Cache.SetValidUntilExpires(false);
        Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetNoStore();
        Response.Expires = -1441;
        Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
        Response.AppendHeader("pragma", "no-cache");
        Response.CacheControl = "No-cache";
        Response.AddHeader("cache-control", "no-store, no-cache, must-revalidate");

Also, I tried inserting this in master page's script:

<meta http-equiv="Expires" content="0"/>
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Pragma" content="no-cache"/>

Figured this out early this morning. Turns out it is just another gotcha when using Ajax. I wasn't adding a History Point before redirecting to a new page when the user selected a row in the datagrid. So i just needed to do a AddHistoryPoint on the scriptmanager before doing the redirect and all was well in the neighborhood.

There are two things I would start with.

First, within the browser, I'd go to Internet Options > Browsing History Settings. If "check for newer versions of the stored pages" is set to Never then I'd move it over to Automatically.

Second, I'd look on the actual file system (not within visual studio, use file explorer) to see if that file was indeed still there. If so, I'd delete it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM