IIS Express does not save session data

I have an application that I am running in Visual Studio 2013 under an IIS Express server. The problem is that session data is not stored between pages and I find null objects that weren't empty before. If I compile the application and deploy it to a web server with IIS it works fine, so it must be something with IIS Express. I've searched for config files in document folders but don't really know what they are.

Thanks Luke

Edit 25/11: I am debugging code on the same machine with VS 2013 and VS 2010 and I found that the code behaves differently. After the code has been executed and the page has been built, execution exits in VS 2010. In VS 2013, after the page has been built, I get another call to the context_BeginRequest (object sender, EventArgs e) method, which redirects the application to the start page, where the Session.Clear () command clears the session. Now the problem is this: why is there an additional call to the context_BeginRequest method? Why is it redirected to the start page and not the page it is currently on? Thanks, Luke.

+3


source to share


2 answers


I had a similar problem. My code worked fine on the production server, but when I debugged it on my test machine, the session would be zero between save and redirect.

When I set the session state to cookieless, the <sessionState cookieless="true"

session variable will be saved. This was deprecated because it adds the session name to the url.



Upon further consideration, I noticed a line on my .web system <httpCookies requireSSL="true" />

When I commented it out, everything worked as usual.

The problem was that my production IIS server hosted code using https: // and my test IIS Express server only used http. Therefore my insecure cookies were dropped.

+3


source


This is the correct behavior; to understand this, you need to understand how the IIS workflow that hosts the application works. Every time it recycles the workflow, all data will be lost, like rebooting the workflow. Below are your options:

  • Maintain the data you need in server side structures like Session (for each user implementation) or Cache (Application wide), which are dictionary type structures (a pair of key values), so every time you return use the key to return data.

  • Remember, Cache is the perfect solution that can even cover all machines.

  • Another temporary option that you can choose has your data in static data types on the server, now it will not affect the recycling process of the IIS worker process, but even so if the process crashes, losing all data is also not by default will be thread safe. Session or Cash will not be affected by these issues.



Learn more about Cache and Session

Please let me know if you need clarification regarding my answer.

0


source







All Articles