locked
Keep SessionID across refreshes and Postbacks ASP.Net RRS feed

  • Question

  • User585373386 posted

    I had an issue with the Session ID changing everytime I hit refresh on a webpage. A search of the web found the answer on here but I can't add to it and I feel it could do with more information to help out others plus address some of the unanswered questions I came across.

    Original thread here. https://forums.asp.net/t/1846969.aspx?SessionID+must+stay+the+same+but+it+changes+on+every+time+I+refresh+page+

    Thanks to Neodynamic for the answer.

    I would like to expand on that thread though:

    to maintain Session.SessionID across postbacks/refreshes do the following:

    • Add a Global.asax file to your web project in the root directory (In Visual Web Developer 2010, you right click on top of your file tree where it says something like C:\mywebsites\myproject\, then select Add New Item.. , then select Global Application Class and click the Add button).
    • Open the newly created Global.asax file
    • Paste the line below inside the curly braces where it says void Session_Start(object sender, EventArgs e){}

    Session.Add("<g class="gr_ gr_1670 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="1670" data-gr-id="1670">dummyString</g>", "<g class="gr_ gr_1671 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="1671" data-gr-id="1671">dummyValue</g>");

    C#, ASP.Net 4.0.

    Sunday, March 25, 2018 4:28 PM

All replies

  • User475983607 posted
    ASP Session ID persists once Session is set in code. Until then the Session ID changes on each request. The Session docs explain this.
    Sunday, March 25, 2018 5:36 PM
  • User283571144 posted

    Hi tizard,

    I had an issue with the Session ID changing everytime I hit refresh on a webpage. A search of the web found the answer on here but I can't add to it and I feel it could do with more information to help out others plus address some of the unanswered questions I came across.

    As far as I know, the sessionid will change if you don't set the session value.

    If you set the session value, you could find the session id will not change.

    I suggest you could try below codes:

                Session["a"] = "sss";
    
                lblGreska.Text = Session.SessionID;

    Result:

    Best Regards,

    Brando

    Monday, March 26, 2018 8:32 AM