简体   繁体   中英

Automatic redirect to login page after a certain time

I am using form authentication. My code in web.config is:

<authentication mode="Forms">
  <forms loginUrl="~/Home/Index" timeout="5" />
</authentication>

I've used [Authorize] at the head of the actions, that need authentication to access. As my configuration in web.config after five minutes an user is redirected to "../Home/Index" if he/she tries to access an action or load a page that is need authentication to access. Is there any way to do it automatically. I mean if the system is idle, like though no one is using the system after five minutes it will automatically redirect to "../Home/Index" page.

Probably the easiest way is to add a meta-refresh tag to your Layout:

<meta http-equiv="refresh" content="310">

This will tell the browser to refresh the page every 5 minutes and 10 seconds. If the browser refreshes.. your timeout will kick in and redirect the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM