locked
SessionID must stay the same but it changes on every time I refresh page? RRS feed

  • Question

  • User1444011213 posted

    hi,

    I have this code:

    lblGreska.Text = Session.SessionID

    And I need ID of session that current use have so I can track his movement on the site, but every time i refresh the same page (every second) I get diferent SessionID value.

    Any idea?

    Thursday, September 27, 2012 10:41 AM

Answers

  • User-1185172246 posted
    That behavior is explained here http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid.aspx under Remarks. And the solution is to add a dummy value to Session object in the Session_Start event of Global.asax, for example: void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started //This is needed so the SessionID does not change on every postback Session.Add("dummy", "dummy"); }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 27, 2012 11:13 PM
  • User1444011213 posted

    HI,

    I created global.asax file and just replace 3 line of code:

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    Session("init") = 0
    End Sub

    And I think it works now

    Thx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 29, 2012 3:21 AM

All replies

  • User1444011213 posted

    I found solution, in webcofigfile you should add

    <sessionState cookieless="true" regenerateExpiredSessionId="false" timeout="30" />

    Thursday, September 27, 2012 11:34 AM
  • User-1185172246 posted
    That behavior is explained here http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid.aspx under Remarks. And the solution is to add a dummy value to Session object in the Session_Start event of Global.asax, for example: void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started //This is needed so the SessionID does not change on every postback Session.Add("dummy", "dummy"); }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 27, 2012 11:13 PM
  • User1444011213 posted

    Hi,

    Can you please give me a full example of that global.asax file?

    I was wronf with previus post, but I do not fully understand what you meen in your post.

    BR

    Saturday, September 29, 2012 3:05 AM
  • User1444011213 posted

    HI,

    I created global.asax file and just replace 3 line of code:

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    Session("init") = 0
    End Sub

    And I think it works now

    Thx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 29, 2012 3:21 AM