Session.Abandon();
Session.Clear();
Session["user"]=null

i m trying to clear a Session but these methods are not working..how can i clear this Session plz help me.. thnxx

Recommended Answers

In order to completely erase it from memory: Session.remove("YourSessionName").

In order to clear its data if it's a basic string: session("YourSessionName") = ""

Jump to Post

Don't use #2 and #3 line statements. Use Session.Abandon() method.

Jump to Post

All 6 Replies

In order to completely erase it from memory: Session.remove("YourSessionName").

In order to clear its data if it's a basic string: session("YourSessionName") = ""

In order to completely erase it from memory: Session.remove("YourSessionName").

In order to clear its data if it's a basic string: session("YourSessionName") = ""

This is also not working

Don't use #2 and #3 line statements. Use Session.Abandon() method.

Don't use #2 and #3 line statements. Use Session.Abandon() method.

this is also not working...

this is my code

protected void Page_Load(object sender, EventArgs e)
    {
   if (Session["user"] != null)
        {
//some codes
            
        }
        else
        {

            Response.Redirect("Default.aspx");
        }
}



protected void Button1_Click2(object sender, EventArgs e)
    {

     
      
        Session.Abandon();
        Response.Redirect("Default.aspx");
    }

try to kill but still it is alive....

I guess you want to disabled the cache.

Write following line in page_load handler.

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Session.Remove("User");
hope so it works

To remove all Session variable use

Session.Removeall();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.