C#.net webform,避免会话超时丢失数据
我有一位用户抱怨我的 Intranet 网页经常超时。在寻找解决方案时,我发现了这篇文章:
http://forums.asp.net /t/152925.aspx?PageIndex=1
发帖者建议拦截登录页面的重定向,将数据提交到数据库,然后重新授权用户(在用户不知情的情况下)或重定向到登录页面。我的目标是避免用户在表单中输入数据,离开,然后回来提交,却被告知必须再次登录的情况(这很好,如果数据仍然存在并且用户被正确发送)返回原始网络表单)。
有谁知道我如何在我的应用程序的特定页面(不是全部)上完成此操作?
I have a user complaining about frequent timeouts in my Intranet web page. While looking for a solution I found this post:
http://forums.asp.net/t/152925.aspx?PageIndex=1
Where a poster recommends intercepting the redirect to the login page, submit the data to the database, then either reauthorize the user (without their knowledge) or redirect to login page. My goal is to avoid the situation where a user enters data in a form, walks away, then comes back to submit it, only to be told they have to login again (which is fine, if the data remained and the user was sent right back to the original webform).
Does anyone know how I can accomplish this on specific pages in my app (not all of them)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,最简单的方法就是大幅延长
web.config
文件中指定的超时时间。Well, the easy way it to drastically lengthen the timeout specified in the
web.config
file.我将尝试使用 cookie 来保存数据。我的计划是在每个控件更改后更新用户的 cookie,然后向页面的 page_load 属性添加逻辑,以在用户重新登录后填充表单数据。
I'm going to try using cookies to preserve the data. My plan is to update the user's cookie after each control is changed, then add logic to the page_load property of the page to populate the form data after the user is logged back in.
这不一定是微不足道的,但您可以添加一个 ajax 组件,偶尔调用页面以保持会话活动。通过这种方式,您可以延长所需的任何特定页面的会话,而不会影响整个应用程序。
编辑
如果您确实想让会话过期,但保留表单数据,您可以
在 global.asax.cs 文件中实现事件处理程序。这是在表单身份验证重定向发生之前调用的,此时表单数据可供您的应用程序使用,因此您可以将其保留到任何必要的介质上,直到您的用户再次进行身份验证。此外,如果您检查该
属性,它会告诉您请求的是哪个页面。
It's not necessarily trivial, but you can add an ajax component that makes occasional calls to a page to keep the session alive. This way you could lengthen the session for any particular page you need to without affecting the application as a whole.
EDIT
If you really want to let the session expire, but keep the form data, you can implement
event handler in your global.asax.cs file. This is called before the forms authentication redirect happens, and the form data is available to your application at this point, so you can persist it to whatever medium is necessary until your user is authenticated again. In addition, if you check the
property it will tell you which page was requested.