Session abandon. New page loaded but not new SessionID

J

James

My web application is comprised of a Login page and then several other pages
nested in a masterpage. I am using a cookiless="UseUri" session configuration.
I have a linkbutton on the masterpage for logout and when the user clicks
this, code is run that does Session.Abandon() and Server.Transfer("Login.
aspx"). This runs fine, but the url still reflects the old SessionID. Because
of this, if the user decides to login again, the page reloads back to the
login page after entering his information. This reloads the new sessionID and
works from there. Is there a way to stop the 2 page loads of the login page
after the session is abandoned?
 
D

DudeBori82

This one took me FOREVER to figure out. To get a new session ID after
Session.Abandon(); put this line of code right after the abandon:

Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));

This sets the .NET cookie to null and on the same post back it will
regenerate a unique ID and create the new session.

Happy coding!!!
 
J

James

This didn't help. I still have the same result. Is this due to my running
cookieless? I need a solution for the url sessionID.

Thanks.
 
J

James

I figured it out. Here is the code.

public void LogOut(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect("~/Login.aspx");
}

Apparently the ~/ was the key. I initially had just "Login.aspx" as the page
and was doing a Server.Transfer. The above code solved the 2 page login load.
Thanks for your help.

This didn't help. I still have the same result. Is this due to my running
cookieless? I need a solution for the url sessionID.

Thanks.
This one took me FOREVER to figure out. To get a new session ID after
Session.Abandon(); put this line of code right after the abandon:
[quoted text clipped - 5 lines]
Happy coding!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top