Session Fixation in ASP.NET

I’m wondering how to prevent Session fixation attacks in ASP.NET (see

My approach would to this would normally be to generate and issue a new session id whenever someone logs in. But is this level of control possible in ASP.NET land?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Have been doing more digging on this. The best way to prevent session fixation attacks in any web application is to issue a new session identifier when a user logs in.

In ASP.NET Session.Abandon() is not sufficient for this task. Microsoft state in that: “”When you abandon a session, the session ID cookie is not removed from the browser of the user. Therefore, as soon as the session has been abandoned, any new requests to the same application will use the same session ID but will have a new session state instance.””

A bug fix has been requested for this at

There is a workaround to ensure new session ids’ are generated detailed at this involves calling Session.Abandon and then clearing the session id cookie.

Would be better if ASP.NET didn’t rely on developers to do this.

Method 2

Basically just do this in your Login GET method and your Logout method:

if (Request.Cookies["ASP.NET_SessionId"] != null)
   Response.Cookies["ASP.NET_SessionId"].Value = string.Empty;
   Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddMonths(-20);

Method 3

If I am assuming right, you are talking about… The short answer is yes, you have a lot of ways in which you can secure your cookie as well. You shouldn’t be using cookieless session, and while you are using sessions, ensure that you have secured the cookie as well explicitly.

Check this article out…

Method 4

It does generate a new session ID when the user logs in, and kills a session when the timeout occurs, or the user navigates away/close the browser. And you can programmably kill it via Abandon() or remove entries via Remove().

So I’m not sure what the issue is?

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x