Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Generate a new Session ID

Tags:

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.

like image 579
Luke Avatar asked Aug 16 '12 12:08

Luke


People also ask

How can you generate a session ID?

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.

Can session ID be duplicated?

Yes, Session. SessionId can be duplicate.

How is session ID generated in Java?

A session-id is obtained by taking an MD5 hash over 128- bits generated using one of Java's pseudo-random number generators (PRNG).

What is my session ID?

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.


2 Answers

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]

like image 141
stuartd Avatar answered Oct 04 '22 10:10

stuartd


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.

like image 30
Pranay Rana Avatar answered Oct 04 '22 09:10

Pranay Rana