Pankaj
Pankaj

Reputation: 10095

session.abandon is not generating new session

I am using asp.net 3.5

Session.Abandon() is not using the new SessionId.

Session["abc"] = "abc";
Session.Abandon(); //Session id is same as checked in add watch

Upvotes: 1

Views: 2658

Answers (3)

Vamsi
Vamsi

Reputation: 4253

You can Session.IsNewSession to identify wether the sesiion is new one or not instead of using the SessionId, ASP.net reuses SessionId, as suggested in the KB Article you can get around this by programmatic-ally setting the SessionId to null in the client side cookies.

Session.Abandon();
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
Response.Redirect(Request.Path);

Upvotes: 3

Prince Antony G
Prince Antony G

Reputation: 932

Session.Clear() then the session variables clear up but the user remaining in the same session (if you don't want him to relogin for example) and reset all his session specific data.

Session.Abandon() only takes effect after page is completely executed. So the current page that called Abandon still has that same session. All next browser calls will be on a new Session.i.e You lose that specific session and the user will get a new session key.

Upvotes: 2

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93434

Yes, and this is by design. It will reuse the same session ID.

See http://support.microsoft.com/kb/899918

Also

http://weblogs.asp.net/karan/archive/2010/04/26/asp-net-session-state-revisited.aspx

Upvotes: 5

Related Questions