Click here to Skip to main content
11,567,539 members (42,922 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 3-Jan-13 23:43pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
   
Thanks
Turbo_23 at 4-Jan-13 6:04am
   
5+
   
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();

please tell me where to put this code in default.aspx or login.aspx
   
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 at 4-Jan-13 7:25am
   
Put it in your Page_Load event in default.aspx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

hello
i think it helps you

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

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web03 | 2.8.150624.2 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100