Click here to Skip to main content
15,884,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am having 2 webpages login.aspx,default.aspx are their in my web project,
after gave logout from default.aspx am redirecting to login page,back button of browser is pressed means it going to default.aspx , please tell me how to prevent it,it should be as login.aspx
Posted

Please have a look at my blog post on this subject

http://www.dylanmorley.com/blog/post/Web-Development-Disabling-the-back-button.aspx[^]

This is because of caching on the browser and the way browser history works. The short answer to this question is

You don't disable the back button. The back button isn't yours to disable, it's part of my browser and I want it to work.

Usually when people post questions like this, it's because they don't understand how to control the flow of data from the site. In this case, the two things we are concerned with are authentication and caching.



So, add the caching directives to your pages and the user will be forced to reauthenticate before they can view your content again.
 
Share this answer
 
Comments
kalaivanan from Bangalore, India 4-Jan-13 6:02am    
Thanks
[no name] 4-Jan-13 6:04am    
5+
kalaivanan from Bangalore, India 4-Jan-13 6:38am    
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();

please tell me where to put this code in default.aspx or login.aspx
kalaivanan from Bangalore, India 4-Jan-13 6:39am    
this code also

HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));

HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
Dylan Morley 4-Jan-13 7:25am    
Put it in your Page_Load event in default.aspx
Hi,

You can use Try and catch follow the below points it's very easy:

1.create sessions at the click of login button.
2. at the click of logout clear all sessions
3.when you clcik back button u ll navigate to the default page,to prevent this situation you need to use try and catch.

it ll help you if not let me know further.


Thanks.
 
Share this answer
 
hello
i think it helps you

XML
<script type="text/javascript" language="javascript">
window.onkeydown = function(event)
{
if(event.keyCode == 8);
return false;
}
</script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900