Is it possible to generate a new ID for the session using ASP.NET?
I want it to change when someone logs in to my website just before I set their initial session variables.
The session ID is generated using the Random Number Generator (RNG) cryptographic provider. The service provider returns a sequence of 15 randomly generated numbers (15 bytes x 8 bit = 120 bits). The array of random numbers is then mapped to valid URL characters and returned as a string.
Yes, Session. SessionId can be duplicate.
A session-id is obtained by taking an MD5 hash over 128- bits generated using one of Java's pseudo-random number generators (PRNG).
A session ID is a unique number a server assigns to requesting clients. ID stands for identifier and is used to identify and track user activity. This unique ID can be a number code, numerical code, or alphanumeric code. In computer science, a session is a temporary connection between server and client.
You can do this using the SessionIdManager class:
SessionIDManager manager = new SessionIDManager(); string newID = manager.CreateSessionID(Context); bool redirected = false; bool isAdded = false; manager.SaveSessionID(Context, newID, out redirected, out isAdded);
[Code sample is from Anas Ghanem's article]
you can use
SessionIDManager.CreateSessionID Method :
returns a unique session identifier that is a randomly generated number encoded into a 24-character string.
Code
SessionIDManager Manager = new SessionIDManager(); string NewID = Manager.CreateSessionID(Context); string OldID = Context.Session.SessionID; bool redirected = false; bool IsAdded = false; Manager.SaveSessionID(Context, NewID,out redirected, out IsAdded);
Here you can find full detail about hsi : Changing the session ID programmatically.
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