Let's say I have two pages on the same ASP.NET C# WebSite.
I tried to turn off cache declaratively, tried using true for endResponse in my redirect... nothing seems to make a difference.
Never mind everybody! I am a moron! Using Visual Studio Dev Localhost the Redirect was redirecting to the live page! :)
Your web form has a method called Page_Load. This method is called each time your page is loaded. This includes: 1. The first time the page is loaded, e.g., when a user enters the url to it or clicks on a link to it.
The Page object calls the OnLoad method on the Page object, and then recursively does the same for each child control until the page and all controls are loaded. The Load event of individual controls occurs after the Load event of the page. This is the first place in the page lifecycle that all values are restored.
Page_Load() method is called after a preLoad event. With Page_Load() you can set default values or check for postBacks etc.
When you navigate to a page using the Back button, the page is reloaded from memory, and no request is sent to the server.
You can confirm this using Fiddler.
I'm not sure if this is true in all browsers.
The reason for the page executing doesn't affect the page cycle, the Load event always fires when the page is executed.
So, if the Page_Load doesn't run sometimes, it's because the page is cached and doesn't execute on the server. The page can be cached in the browser, in a router somewhere along the way, or on the server using server side page caching.
If you haven't enabled server side page caching for the page, it's cached in the browser or in the network. You can use cache settings to try to elliminate this:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
This will keep the page from being cached in normal circumstances. (Check also that your browser isn't in offline mode, then it will use anything in the cache regardless of it's cacheability settings.)
If you are redirecting, it's possible the client is caching the response. In order to get past this you might add an extra query parameter that simply holds the time.
This is usually enough to get past most pages caching mechanisms.
Try using Server.Transfer instead of Response.Redirect.
The client will not see the URL change but this may not matter, depending on your requirements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With