Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
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

Hello,

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

C#
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
 
Share this answer
 
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
Try this on Home Page_load event
C#
if(Session.count>0)
return;
else
Reponse.Redirect("Login.aspx");
 
Share this answer
 
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
priya ji...
have U written this...?
on
C#
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
C#
Page_Load
{
if(!isPostback)
  {
   if(Session("ESrNo")<=0)
     {
      Response.Redirect("Login.aspx");
     }
     
  }
}

Hope It Will Work...
 
Share this answer
 
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)



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