locked
Changing Session ID Manager using PreApplicationStartMethod RRS feed

  • Question

  • User-622037679 posted

    I know we can change Session ID Manager via webconfig like ;

    <sessionState sessionIDManagerType="SampleSessionIDManager" />

    Is it possible to change Session ID Manager using PreApplicationStartMethod? Or is there any way to change programmatically.

    Thank you

    Tuesday, April 29, 2014 5:55 AM

All replies

  • User697462465 posted

    Hi Blink-Striker,

    Welcome to ASP.NET forum.

    If you want to change sessionid programmatically, please try to refer to the following 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); Response.Write("Old SessionId Is : " + OldID);
            if (IsAdded)
            {
                Response.Write("<br/> New Session ID Is : " + NewID);
            }
            else
            {
                Response.Write("<br/> Session Id did not saved : ");
            }

    Hope it helps.

    Best Regards,
    Terry Guo

    Tuesday, April 29, 2014 9:38 PM
  • User-622037679 posted

    Hi, 

    Thank you for your answer. But I don't want to change Session Id, i want to change Session ID Manager. I already inherit and override SessionIDManager class. And configure like 

    <sessionState sessionIDManagerType="MySessionIDManager" />

    Here is the msdn link about changing SessionIDManager via web config

    But what i want is changing SessionIDManager programmatically. My guess is its must be some way on PreApplicationStartMethod

    Friday, May 9, 2014 3:08 AM