Asp.net mvc session timeout

How to implement session timeout function for asp.net mvc application? I want the user to automatically log out as soon as inactivity is detected during the grant time period.

I can implement ActionFilterAttribute and apply to each method, but it will not automatically log out. It will exit only when the user tries to call a method for this action.

Thanks.

+6
source share
2 answers

This is because the session is supported on the server side. if you want the unoccupied page in the user browser to be automatically written out, you need to write javascript for it. you can use the ajax request to check if the session has ended or not, and depending on the result, you can redirect the user to the index (login or any other page that does not require authentication).

+4
source

You should be able to manage this from web.config:

<system.web> <sessionState timeout="x"/> ... </system.web> 

I am not an MVC expert, but changing this behavior deployed to ASP.NET is not something I expect.

This can also be configured using the IIS management application; it is not determined which version of IIS you are using, but in this article Technet describes what should be easy to follow even in older versions (prior to IIS7). Note that behind the scenes this method still controls the settings in the web.config file, so if it is versioned, I would not recommend changing it that way.

+12
source

Source: https://habr.com/ru/post/886635/


All Articles