Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi there..
in my project a user can sign in and access her home.aspx page and can hit signout link_button for signout, but when back button pressed then again home.aspx page is shown there.
I want that when signout button clicked then it go to login page and back is disabled.. How can i treat it in pagebehind C#. i mean when signout link button pressed a matthod is called that disable the back button.....
please give me some code for C# to disable back


my code is---

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["expire"] == "True")
{
//
//WHAT SHOULD I WRITE HERE
//
}
SqlConnection con = new SqlConnection("server=.\\SQLEXPRESS; AttachDbFileName=|DataDirectory|\\Database.mdf; user instance=true; trusted_connection=yes");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT fn,ln FROM signup WHERE id='"+Session["User"]+"'",con);
SqlDataReader rd = cmd.ExecuteReader();
while (rd.Read())
{
Label1.Text = rd.GetString(0).ToString();
Label2.Text = rd.GetString(1).ToString();
}

}

protected void LinkButton1_Click(object sender, EventArgs e) //for Signout
{
Session["User"] = "";
Session["expire"] = "True";
Response.Redirect("login.aspx");
}



}


here LinkButton1_Click for signout. As Signout Clicked session["expired"] goes true.
as sign button clicked loginpage displayed. NOW as back button is clicked so this page is loded again and session["expire"]=true checked ... so in pageload field what should i write so that back cannot load it again...
Posted

 
Share this answer
 
XML
<script language="JavaScript">
window.history.forward(1);
</script>


Try this..
 
Share this answer
 
I can give you the code because i also face that problem and solve it using session.You need to clear the session of browser when you log out from your page.
After successfull login in page load event add these lines..
C#
Response.ClearHeaders();
Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
Response.AddHeader("Pragma", "no-cache");

and then in log out button code write..
C#
Response.Redirect("Login.aspx");

Session.Abandon();
Session.Clear();
 
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