How to Kill A Session or Session ID (ASP.NET/C#)

how to destroy session in on logout
kill session using session id in asp net
session id in asp net c# example
invalidate old session id after authentication asp net
asp net session
asp net session w3schools
how to set session in asp net
asp net clear session

How can I destroy a session (Session["Name"]) when the user clicks the logout button?

I'm looking through the ASP.NET API Reference on MSDN and it doesn't seem to have much information. It seems rather limited. But I cannot find any other pages for ASP.NET Classes etc.

I have tried:

Session.Abandon(); and Session.Contents.Remove("Name"); neither of them work. ( I found these in a forum from a Google search)

The Abandon method should work (MSDN):


If you want to remove a specific item from the session use (MSDN):


EDIT: If you just want to clear a value you can do:

Session["YourItem"] = null;

If you want to clear all keys do:


If none of these are working for you then something fishy is going on. I would check to see where you are assigning the value and verify that it is not getting reassigned after you clear the value.

Simple check do:

Session["YourKey"] = "Test";  // creates the key
Session.Remove("YourKey");    // removes the key
bool gone = (Session["YourKey"] == null);   // tests that the remove worked

Developers Field: How to Kill A Session or Session ID (ASP.NET/C#), How to Kill A Session or Session ID (ASP.NET/C#). Below are the differnt ways to remove the sessions:- 1. Session.Remove(strSessionName);� Session.Abandon() this will destroy the data. Note, this won't necessarily truly remove the session token from a user, and that same session token at a later point might get picked up and created as a new session with the same id because it's deemed to be fair game to be used.

It is also a good idea to instruct the client browser to clear session id cookie value.

Response.Cookies["ASP.NET_SessionId"].Value = string.Empty;
Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddMonths(-10);

[Solved] how to kill the session from Unique sessionID, Varushali, You can try this:- call 'getSingleLogin("UserName'")' Method Before Login Process. Hide Expand Copy Code. I guess it depends a bit on the code you're doing but the basic operation would be if you have "Logout" button on a page that in the code does a session.abandon() call then redirects to your homepage. the loading of the homepage should have a new session and thus not be "logged in" anymore. they will have a new session but all data associated with the old session is gone.


This marks the session as Abandoned, but the session won't actually be Abandoned at that moment, the request has to complete first.

Kill session ID, ID for user. now when user login with an ID his session id is inserted along with userid and i chk this table if theres a user1 already logged in then� This article will show you how you can kill or remove a session in your mvc application. So there are three ways by which we can remove the session in mvc Session.Abandon, Session.Remove and Session.Clear. So here i will show code for using this. Session.Abandon:

From what I tested:

Session.Abandon(); // Does nothing
Session.Clear();   // Removes the data contained in the session

001: Session["test"] = "test";
002: Session.Abandon();
003: Print(Session["test"]); // Outputs: "test"

Session.Abandon does only set a boolean flag in the session-object to true. The calling web-server may react to that or not, but there is NO immediate action caused by ASP. (I checked that myself with the .net-Reflector)

In fact, you can continue working with the old session, by hitting the browser's back button once, and continue browsing across the website normally.

So, to conclude this: Use Session.Clear() and save frustration.

Remark: I've tested this behaviour on the development server. The actual IIS may behave differently.

Killing a remote session from a different session., I'm not using Forms authentication. This is the problem. Also it appears you are comparing the session id to the current browser session. How do I� I am not asking to kill session on logout, I just want if user are on dashboard.aspx page when he click on any link and leave this page dashobard.aspx and reach on dashoarddetails.aspx page. Then the session i am using on dashobard should kill when he left dashobard page.

Session.Abandon() this will destroy the data.

Note, this won't necessarily truly remove the session token from a user, and that same session token at a later point might get picked up and created as a new session with the same id because it's deemed to be fair game to be used.

Kill Session when Clicking logout, Hello Everyone,, Help me to kill the session when clicking logout. Heres the < asp:LinkButton runat="server" ID="lnkLogOut" Text="Logout" Session.Abandon() used to destroys the session and we can not use that session till running web form. The Session.Abandon() kills the current Session Id in ASP.Net. Session.Clear()

How to kill a user's session [duplicate] - - iOS, This question already has an answer here: How to Kill A Session or Session ID ( ASP.NET/C#) 9 answers In an MVC application, a user has logged in Machine1. If your application requires a static session ID for the entire session, you can either implement the Session_Start method in the application's Global.asax file and store data in the Session object to fix the session ID, or you can use code in another part of your application to explicitly store data in the Session object.

Session resets on redirect - c# - csharp, Redirect("~/SomeDirectory/Default.aspx"); However it clears out the Session How to Kill A Session or Session ID (ASP.NET/C#). How can I destroy a session� i have count the number of online user to the web server. i have created the username & assign the password to individual computer then using this user name user can access the main page & after login user i have add the username ,session ID,ip address in datatable. if i user already connected from another computer then same user access the information from another computer then user first

Assign and Access Session Variables from a Class in Asp.Net C# , Assign and Access Session Variables from a Class in Asp.Net C# and Vb.Net The recorded sessions are used throughout the website (pages) until either the session is killed explicitly or it is over. Assigning Session from Code behind (C #) The E-mail ID will be verified in a Class and the employee full name will be� So, data in the session is available as long as the session is alive. In the State Server mode, the session data is stored in a separate process - this is called the ASP.Net State Service.

  • What do you mean by "neither of them work"
  • Um... When I output the contents of the session["Name"] it still outputs the name, but it shouldn't because it should've been cleared or killed. And it doesn't Sign me out. So, that's what I mean by "Neither of them work"
  • Try adding a redirect back to the login page, check for the Session["Name"] in there.
  • May be this link might help you.
  • The Abaondon Method works all you need to do is take of the postbackurl from the html script and add a redirect after Session.Abandon().
  • Thanks, @Kelsey; I just updated my question to show what I've already tried. The Abaondon Method doesn't work :S
  • @Lucifer are you trying to kill the Session from the current session or are you trying to do it from the application level and locate and kill a specific session?
  • Um, from the current session,?
  • @Lucifer something else is going on I suspect. I have editted my answer to include a little check and some other options.
  • @Lucifer What result were you expecting? The value will be null after the Remove. Did you want something more to happen?
  • is this really necessary ? Response.Cookies["ASP.NET_SessionId"].Value = string.empty ? or just with Session.Abandon() is enough ?
  • Thanks @Chris, I've tried that, and it still outputs the contents of the session["Name"] and won't signout.
  • If you're just trying to remove the 'Name', you can do Session.Remove("Name"); or clear it using Session["Name"] = null;