SCENARIO:
Created a simple login that checked user name and password against a database and then sent user to the proper page if verified. (also writing a ‘logged in’ session variable)
Within the pages Page_Load event, I check for the proper session variable and if not present send them back to login screen.
Additionally, I added a logout link that wiped the variable and sent them back to login….
THING all appeared to work great… UNTIL I tried to navigate straight to a page AFTER logging out. The page was able to be accessed EVEN though I had logged out AND my Page_Load event was not even getting called.
====
REASON/SOLUTION:
The pages were being cached and therefore did not need to check the Page_Load event which would have caught the fact that the user was not properly logged in…. The solution is to place the following code in your Load event.
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
** This is not a proper solution for a large solution with a lot of pages but for this purpose I only had one Default page with user controls … if you have many pages you should use the auth ticket option.
