Tuesday, May 13, 2014

Session Id changes in ASP.NET MVC on every new page request

I faced and issue in ASP.NET MVC application where the value of SessionID variable changes on consecutive page requests.

The reason is either you don't have a Global.asax file in your solution, or you have a global.asax in your solution without the definition of session end and session start. So the web server actually doesn't take care of session start and end event per application basis, and it generates a new key on every page request.
You should have a Global.asax in your project and it shall have following two functions added:

       protected void Session_Start()
        { }

        protected void Session_End()
        { }

This should work perfectly.......
Enjoy coding!

No comments:

Visual Studio Build Error - The "GenerateResource" task failed unexpectedly

Error: "The GenerateResource task failed unexpectedly" This error is quite common while building the project in Visual Studio....