|
-
July 10th, 2006, 05:14 AM
#1
Issues with browsers BACK and FORWARD buttons
HI
I have developed a web site. In the web site, the user can see view his details if he has logged in. In case user has not logged in, then the login screen is displayed, where the user logs in . In the details page, if the user clicks on the browser BACK button, he is taken back to login screen, but the password is not displayed.
Now, the user can again click on the browser's FORWARD button to view the account details.
I don't want this to be working this way. Even if the user clicks FORWARD button, he should not be able to proceed to details page without entering the pasword in login screen.
How can I do this with ASP.NET ?
Thanking in Advance
-
July 10th, 2006, 05:48 AM
#2
Re: Issues with browsers BACK and FORWARD buttons
The moment you redirect the user to the Login Page you should be clearing the Session variables. And all the other pages before displaying any data should check the session variables and if they are empty the user should then be taken back to the Login Page.
I am assuming that the once the user logs in a session variable is created for him/her which will be used through the application.
-
July 10th, 2006, 10:53 PM
#3
Re: Issues with browsers BACK and FORWARD buttons
I m clearing all the session variables, but if the user clicks the BACK button provided by the IE on top, to go back to the login screen and again if the user clicks the FORWARD button provided by IE, the user can access the details page without logging in.
I want to avoid this,
Is there any way to capture the browser's BACK and FORWARD button click events ?
-
July 11th, 2006, 12:56 AM
#4
Re: Issues with browsers BACK and FORWARD buttons
 Originally Posted by rahulvasanth
I m clearing all the session variables, but if the user clicks the BACK button provided by the IE on top, to go back to the login screen and again if the user clicks the FORWARD button provided by IE, the user can access the details page without logging in.
I want to avoid this,
Is there any way to capture the browser's BACK and FORWARD button click events ?
Did you try doing what is suggested in my previous post?
-
July 11th, 2006, 03:57 AM
#5
Re: Issues with browsers BACK and FORWARD buttons
Clear your login session variable in pageload of your login.aspx.
Check this session in all your other modules, if its nothing redirect to login.
add these two lines of code in the pageload of each module you don't
want to allow to go by browers back/forward button:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1))
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Cheers,
Andy
-
July 11th, 2006, 12:03 PM
#6
Re: Issues with browsers BACK and FORWARD buttons
Actually, when user click "back" button to go to login webpage, server side code won't run. So it is useless to write code in page_load.
The better way is to set cookie for that. Because javascript code will run when the webpage is showing by whatever way.
the code in login.aspx:
Code:
window.onload = function(){ document.cookie='logged=;expires=Thu, 01-Jan-1970 00:00:01 GMT;';
document.getElementById('hidLogged').value = 'false';
};
window.onunload=function()
{
if (document.getElementById('hidLogged').value == 'true')
{
document.cookie='logged=true;';
}
};
the code in default.aspx:
Code:
window.onload = function(){if(getCookie('logged') == null){window.location.assign('Login.aspx');return;};};
You can try that.
-
July 12th, 2006, 04:16 AM
#7
Re: Issues with browsers BACK and FORWARD buttons
why is it useless?
The code is executed once you load the page, so browsers caching for that
page is no longer active.
Absolutly no need for javascript.
-
July 12th, 2006, 06:13 AM
#8
Re: Issues with browsers BACK and FORWARD buttons
The page_load event is not triggered when I use the browser's BACK and FORWARD button
I think the browser loads the pages from its memory.
-
July 12th, 2006, 06:36 AM
#9
Re: Issues with browsers BACK and FORWARD buttons
Yes the Browser usually cache the Pages and when the same page is asked it will load it from the Cache.
-
July 12th, 2006, 10:00 AM
#10
Re: Issues with browsers BACK and FORWARD buttons
 Originally Posted by AndyTheAce
Clear your login session variable in pageload of your login.aspx.
Check this session in all your other modules, if its nothing redirect to login.
add these two lines of code in the pageload of each module you don't
want to allow to go by browers back/forward button:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1))
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Cheers,
Andy
Andy's method does work. However, how can you do when you have many pages under security control. For example, after login you wanna go back to the first page from the second page, can you?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|