Search code examples
asp.net-mvc-4session-timeoutsession-management

Session timeout in mvc application


How should I use the tag in the web.config in my MVC4 application, framework 4.0?

I added it in the web config like this:

<sessionState timeout="15"  />

but it didn't time out.

Also I can't understand for certain what it means if I set mode="StateServer" or mode="InProc" In the msdn it say about "InProc" - "Session state is in process with an ASP.NET worker process." But I don't know how to understand it and which one to choose.

Thank you.


Solution

  • configure it in the web.config:

    <authentication mode="Forms">
        <forms defaultUrl="~/Default.aspx"
            loginUrl="~/Login.aspx"
            slidingExpiration="true"
            timeout="60" />
    </authentication>
    

    With the configuration above, the user will be always redirected to the Login.aspx page when their session expires. There is a timeout of 60 minutes, and sliding expiration means that the timeout is extended each time the user makes a request to the web application, so if he stays active the session will not expire. A configuration like this gives you another advantage over what you tried to do - once the user logs in he will be automatically redirected back to the resource he originally requested. And you can always override and customize this behavior.