How to create a session id for every login in Asp.net MVC?

I am new to MVC, I want to get a new sessionId for each login, because I get like

string sessionId=HttpContext.Current.Session.SessionID; 

But it generates the same session for each input.

I used to delete or clean up the session as shown below:

  Session.Abandon(); Session.RemoveAll(); Session.Clear(); 

But there is no change in the generying sessionid for each entry. Is there an alternative to creating a new sessionId for each login?

+6
source share
4 answers

I have a better solution for creating a new session id like

 SessionIDManager manager = new SessionIDManager(); string newSessionId = manager.CreateSessionID(HttpContext.Current); 

The above code helped me.

+9
source

Try this when you leave the session / Logout:

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

By clearing this cookie, a new session with a new session identifier will be created after the second login.

+12
source

If you are using Framework 4.0, this worked for me:

 using System.Web; ... string sid = HttpContext.Session.SessionID; 
-1
source

Simply create, perhaps, a table (or another column for the user table) and write down when the user is inside the website. Something like a flag to determine that the user is currently logging in. Do some work to check and write the user out for a while, the administrator can presumably manually kill the session.

-3
source

Source: https://habr.com/ru/post/972014/


All Articles