1
votes

I am using MVC5. at every 15 minute or before it session is expired below is the code that i have added in web.config file

authentication mode="None" sessionState mode="InProc" timeout="20" Please Help me. Thank you

4
where is code you have added?Abhay Dixit
You seem to be confusing Session and Authentication. They are two different things. Which do you mean? Does it require you to log in again, or are your session variables disappearing?Erik Funkenbusch
I think this will be useful for you: stackoverflow.com/questions/17741775/…Alsamil Mehboob
In @AlsamilMehboob 's link there is an answer containing the right way to write the <authentication> and its child <forms> tag: https://stackoverflow.com/a/17741890/1361831Tiramonium

4 Answers

2
votes

InProc session storage is in-memory and tied to the process. In other words, it's volatile: both because the memory can be reclaimed and the process can be killed. In particular the App Pool is set to recycle periodically by default and can also crash, or IIS or the server itself could be restarted. All of these will destroy any active sessions.

InProc is really only viable in development, to save you from having to set up an actual session store, just to play with some code. In production, you should always be using something else, like SQL Server or Redis. Even in development, it's important to realize that, again, since it's tied to the process, doing something like stopping and restarting debugging will kill the IIS Express process and thus your session state.

0
votes

You can increase the session timeout by adding below lines in web.config

timeout in Minutes

<sessionState timeout="120">
</sessionState>
0
votes

If you're hosting your website in IIS and you've not made any request to your website for 15 minutes, then it's likely the app pool has been recycled. It means that any data that was stored in memory (like the session state as you specified mode="InProc") has been lost and a new thread was created when accessing the website after 15 minutes. You would easily notice if this is the case as the app pool start up time can take 10 to 30 seconds - which explains why the first request take so long to render and subsequent requests are much faster.

If this is happening on your local machine, any re-compilation of your code would have the same effect.

Another possibility is that you are behind a load balancer and that the second request doesn't go to the same physical server which served the first request. (obviously, the second server has no knowledge of what's in memory on the first server)

For those reasons, it's best to avoid mode="InProc". You wouldn't want to use mode="InProc" in production, and it's better to stick with the same settings in Development, so you can see any issues early.

0
votes

I have a similar setup

<sessionState mode="InProc" cookieless="false" timeout="20" />

setting it to 20 minutes.