I am new to MVC, I want to get new sessionId for everylogin, for that i am getting like
string sessionId=HttpContext.Current.Session.SessionID;
But, it is generating same sessionid for every login.
I have used to remove or clear session like below:
Session.Abandon();
Session.RemoveAll();
Session.Clear();
But there is no change in genereating sessionid for every login. Is there any alternative to create new sessionId for every login?
Try this when you abandon session/Logout:
Session.Abandon();
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
By clearing out that cookie, a new session with a new session ID will be created after second login.
I got better solution to create new session id like
SessionIDManager manager = new SessionIDManager();
string newSessionId = manager.CreateSessionID(HttpContext.Current);
above code helped me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With