Reset SessionID in Asp.Net Web Application

How to Change or Reset SessionID in Asp.Net Web Application

December 2, 2020

In this article we will cover how to Reset or Generate new Asp.Net SessionID

To reset or change Asp.Net Session ID, will need to use SessionIDManager class

Create below mentioned function to save the new Session ID. This function will create a new Session ID and save it in Current Context

public void Reset_SessionID()
{
    SessionIDManager manager = new SessionIDManager();
    string newID = manager.CreateSessionID(Context);
    bool redirected = false;
    bool isAdded = false;
    manager.SaveSessionID(Context, newIDout redirectedout isAdded);
}

Call above Function to create new Session ID

protected void Page_Load(object senderEventArgs e)
{
    string curSID= Session.SessionID; // SessionID when first time page load
 
    ResetSessionID();
}

Post Comments(0)

Leave a reply

Will not be displayed in comment box .

Loading...