Code Snippet posted by:
Lakhwinder.ghuman | Posted on: 6/28/2011 | Category:
C# Codes | Views: 13066 | Status:
[Member] |
Points: 40
|
Alert Moderator
Prevent the Back option after Log Out:
To prevent the user to go back on your web page once the user has logged out , follow the procedure as:
Step 1 Set a Session in the Login Page after proper validation of User Id and Password. For e.g.
Session["LoginId"]=txtLoginId.Text;
Step 2 In the Page_Load event of your master page include the following code:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
if (Session["LoginId"] == null)
Response.Redirect("frmLogin.aspx");
else
{
Response.ClearHeaders();
Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
Response.AddHeader("Pragma", "no-cache");
}
}
}
Step 3 Do clear the session on the Logout button as:
Session.Abandon();
Session.Clear();
By default when you press the browser's back button , it loads the page directly from the browser's cache but by implementing the code given in the step 2 , the page will be loaded and the page load event will fire. Best Regards
Lakhwinder Ghuman