ASP.Net Session ID Changes Every Request

Just a small note on a problem I just had.  ASP.Net provides an ID for the current session which can be especially useful for tracking statistics about the user.  Normally you expect all requests from a single user to come in with the same session ID however that was not the behaviour I was seeing today.

It turns out that unless you make a change to the session data, the session will not be persisted and a new one will be generated for the next request.  Something like this placed in you Global.asax file should do the trick:

    public class Global : HttpApplication

    {

        protected void Session_Start(object sender, EventArgs e)

        {

            Session["PersistMe"] = true;

        }

13/12/2008 10:37 PM (UTC -08:00)