Yes, sure we can modify the session id after login.
Creating Session-id according to our choice as-
References -
Creating Session-id according to our choice as-
SessionIDManager manager = new SessionIDManager();
var newId = manager.CreateSessionID(Context);
var isRedirected = false;
var isAdded = false;
manager.SaveSessionID(Current, newId, out isRedirected, out isAdded);
but still not used the newly generated Session-id. If used Session.Abondon() method to clear the Session state but it also can't achieve our goal because we don't remove the cookie from the browser which holds the Session-Id So, once new request is come in our application it used the previous one not the new one.Also create a new cookie and stored the newly generated Session-Id.Session.Abandon(); Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));The above code will resolve the problem and will used the newly generated Session-Id.
References -
When the Web application requires a logon and offers a log off page or option, we recommend that you clear the session state when the user has logged off the Web site. To clear the session state, call the Session.Abandon method. The Session.Abandon method lets you flush the session state without waiting for the session state time-out. By default, this time-out is a 20-minute sliding expiration. This expiration is refreshed every time that the user makes a request to the Web site and presents the session ID cookie. The Abandon method sets a flag in the session state object that indicates that the session state should be abandoned. The flag is examined and then acted upon at the end of the page request. Therefore, the user can use session objects within the page after you call the Abandon method. As soon as the page processing is completed, the session is removed.
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.
Sometimes, you may not want to reuse the session ID. If you do and if you understand the ramifications of not reusing the session ID, use the following code example to abandon a session and to clear the session ID cookie:
Session.Abandon(); Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
This code example clears the session state from the server and sets the session state cookie to null. The null value effectively clears the cookie from the browser.
So the previous value stored in the previous sessionid session is null now.
You could access to the below links for more information:
For remaining this values, you could try to store them in the database or try to use Application state. For further information, you could refer to:
After enter session .abondon();
ReplyDeleteit remove all other customized session in the application.