Heena
Heena

Reputation: 754

Logout in c# not working

I am having below code for logout. when It gets log out but when back is pressed it should not go to previously visited page but it does.

//when login

if (txtPassword.Text == password)
                {
                    Session["Login"] = true;
                    Response.Redirect("AdminControlPanel.aspx");
                }

//when logout

Session["Login"] = false;
            Session.Abandon();
            FormsAuthentication.SignOut();
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetAllowResponseInBrowserHistory(false);
            Response.Redirect("~/index.aspx");

//checking on adminpanel.aspx

if (!this.Page.IsPostBack)
            {
                if (this.Session["Login"]==null || (bool)this.Session["Login"]==false)
                {
                   base.Response.Redirect("~/index.aspx");
                }
            }

what is wrong with this?

Upvotes: 0

Views: 591

Answers (2)

huMpty duMpty
huMpty duMpty

Reputation: 14460

May be there may be problem when you assigning the value to the session variable

put a break point in if (txtPassword.Text == password) and check what happens.

also

if (!this.Page.IsPostBack)
            {            
             if (!string.IsNullOrEmpty((string) Session["Login"]))
             {
                  var result = Convert.ToBoolean(Session["Login"]); //put a break point there also and check what values it getting
              }


            }

Upvotes: 0

KV Prajapati
KV Prajapati

Reputation: 94645

Try to set Cache-Control.

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetAllowResponseInBrowserHistory(false);

Upvotes: 3

Related Questions