开发者

Preventing Session Timeouts in asp.net mvc

开发者 https://www.devze.com 2023-01-04 12:41 出处:网络
i have a form where user enter some information. The problem is when they submit the form, due to session timeout, the page redirected to login page. After login they return to the same page but the f

i have a form where user enter some information. The problem is when they submit the form, due to session timeout, the page redirected to login page. After login they return to the same page but the form is empty and all information is lost which is very annoying for the user.

What is the best 开发者_StackOverflow中文版solution? I don't want to refresh the page. Should I send ajax request after every 5 minutes.

NOTE: The current Session Timeout is 40 minutes and it is stored in database.


If sliding expiration is enabled you could indeed poll the server at regular intervals to ensure that the session doesn't expire.


Pass the formcollection to the logon page to pass back to the form after redirecting.

EDIT: You can modify the action that the form posts to so that instead of sending unauthorized users to the logon action strait away you can have it first check if the user is authenticated then if not save the data somewhere (sql table or a cookie should be fine) and send the user to the logon action or continue to handle the data as normal. Have a parameter passed to the form action that indicates if and where to retrieve the saved data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号