hi friends
I have login in my application.In every page I am checking Session["UserId"] is null or not.If null I am redirecting to Login page.But when user clicks on browser back button it redirects to previous page and it giving object reference error.
So how to prevent this when user clicks browser back button after logout it should display only login page.
Thanks in advance
Krishna Rajput SinghPosted Sep 25, 2016, 8:13 AM
Midhun TpPosted Sep 25, 2016, 4:15 AM
This error may be happening because you may be checking session is null as below -
if(Session["username"].ToString()!="")
You should check session is empty like below-
if(Convert.ToString(Session["username"])!="")
Also you should delete session value in logout button click using below code-
Session.Abandon();
Guest UserPosted Sep 25, 2016, 2:01 AM
page 1(default.aspx)
page 2(Default2.aspx) in page load
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Response.Cache.SetNoStore();
if (Session["id"] == null)
{
Response.Redirect("Default.aspx");// redirects to page1(default.aspx)
}
else
{
Label1.Text = (string)Session["id"];//just display user name in label
}
}
In page 2 log out button