会话超时 注销用户

发布于 2024-09-26 21:03:54 字数 95 浏览 3 评论 0原文

我希望我的应用程序在会话超时后立即注销已登录的用户并将他们带到 Loing.aspx 页面。用户应该注销而不触发任何事件。我尝试过更改身份验证模式,但一切都是徒劳的......

I want my application to log out the logged in user and take them to the Loing.aspx page as soon as the Session times out. The user should be logged out without any event being triggered. I have tried making changes in authentication mode but all in vain...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凑诗 2024-10-03 21:03:54

Web 窗体与 Windows 窗体不同,但您可能会稍微使用一下。

您无法捕获 Session.End 事件并将用户重定向到其他地方,但您可以使用 cookie。会话过期,cookie 的过期由您的代码控制。

我想到的第一件事是在登录后设置一个 cookie,然后在每个页面加载时检查

if (cookie is present && Session["LoggedIn"]==null)
    Response.Redirect("Login.aspx");

这是一个粗暴的手写伪代码,可能会帮助您提出想法。

但另一个问题出现了:如果您处于受保护区域并且会话过期,ASP.NET 一旦配置好身份验证就会自动将您带到登录页面。

我所说的“良好配置”是指遵循所有标准程序在 Web 应用程序中创建保护区并使用表单身份验证:RTFM http://www.asp.net/security/tutorials/an-overview-of-forms-authentication-vb

Web Forms are not like Windows Forms, but you might play with it a bit.

You can't catch a Session.End event and redirect the user to somewhere else, but you might play with cookies. Sessions expires, cookies' expiration is controlled by your code.

The first thing that comes into my mind is to set a cookie after login, then at every page load check

if (cookie is present && Session["LoggedIn"]==null)
    Response.Redirect("Login.aspx");

This is a brute hand-written pseudo code that might help you make an idea.

But another question rises: if you are in a protected area and session expires, ASP.NET, as soon as you configured authentication well should automatically bring you to the login page.

By "well configuring" I mean following all the standard procedure to create protected areas within your web application and using Forms authentication: RTFM for that http://www.asp.net/security/tutorials/an-overview-of-forms-authentication-vb

狂之美人 2024-10-03 21:03:54

如果您的表单身份验证已正确设置(如此处提到的),并且给定无论如何,您不想在会话超时时捕获任何事件,那么理想情况下,如果用户处于非活动状态 20 分钟(这是默认会话超时时间,除非您更改它),应用程序将自动将任何下一个请求重定向到 Login.aspx。但请确保您遵循上述链接中给出的所有步骤(基本上正确的身份验证和授权标签等)。

If your forms authentication is properly setup (Like mentioned here) , and given that you anyways don't want to trap any event on session timeout, then ideally if user is InActive for 20 mins (which is the default session timeout time unless you changed it), application would automatically redirect any next request to Login.aspx. But make sure that you followed all steps given in the above link (basically correct authentication and authorization tag etc).

別甾虛僞 2024-10-03 21:03:54

尝试在 web.config 中的 下添加以下标记

Try adding following tag under <system.web> in web.config

<sessionState mode="InProc" timeout="200"></sessionState>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文