Click here to Skip to main content
12,396,961 members (43,032 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
I have two pages, Login.aspx and Home.aspx.
Home.aspx contains a logout button- btnLogOut, when user clicks on logout button, then session ends and user gets redirected to Login page.

Problem is that when i press browser back button Home.aspx gets visible, is there any simple way to stop it
Posted 23-Nov-12 1:58am
pryashrma1.1K
Comments
ridoy 23-Nov-12 9:01am
   
you need to use just Session.Abandon()
pryashrma 24-Nov-12 4:55am
   
it doesn't stop browser from showing the prev. page on 'back' btn click
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Hello,

Just write this blow given code in logout.cs page.

protected void Page_Init(object Sender, EventArgs e)
  {
      Response.Cache.SetCacheability(HttpCacheability.NoCache);
      Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
      Response.Cache.SetNoStore();
  }


Thanks,
Abhimanyu Rawat
  Permalink  
Comments
pryashrma 24-Nov-12 0:52am
   
this is the logout code... but it doesn't restrict browser from showing previous page, when back button is clicked
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this on Home Page_load event
if(Session.count>0)
return;
else
Reponse.Redirect("Login.aspx");
  Permalink  
Comments
pryashrma 24-Nov-12 0:53am
   
don't have problem with logout code...
problem is to restrict browser from showing previous page, when back button is clicked if user logouts
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

priya ji...
have U written this...?
on
logout_Click
{
formsAuthentication.signout();
session.Abandon();
Response.Redirect("Login.aspx");
}
Now session is abandon So session variable wiil not have a value...
so u can redirect in Page_Load of Home.aspx
Page_Load
{
if(!isPostback)
  {
   if(Session("ESrNo")<=0)
     {
      Response.Redirect("Login.aspx");
     }
     
  }
}
Hope It Will Work...
  Permalink  
v2
Comments
pryashrma 24-Nov-12 0:53am
   
don't have problem with logout code...
problem is to restrict browser from showing previous page, when back button is clicked
Devang Vaja 24-Nov-12 1:33am
   
priya ji if u put redirct code which i have written in page load not is postback than user will not be able to use home page on clicking back button coz session would be expired..
pryashrma 24-Nov-12 4:53am
   
it doesn't stop browser from showing the prev. page

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2016
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