如何在asp.net中销毁当前用户以外的其他用户的会话

发布于 2024-09-10 16:04:01 字数 261 浏览 7 评论 0原文

我将 asp.net 4.0 与 asp.net MVC 2.0 和 asp.net 会员资格提供程序一起使用。

我需要在删除用户会话之前终止它。否则,如果用户下次访问页面时仍通过身份验证,则在尝试访问用户数据和配置文件时将发生空引用异常。

我得到了 Session.Abandon() 方法,但我正在寻找的内容在用户上是相同的,例如 user.AbandonSessions() 。

我意识到这个问题以前曾被问过,但我无法得到直接答案。

谢谢

I'm using asp.net 4.0 with asp.net MVC 2.0 and the asp.net membership provider.

I need to terminate a the user session before I delete it. Otherwise if the user is still authenticated the next time it will visit a page null reference exceptions will occur when trying to access the user data and profile.

I get the Session.Abandon() method but what I'm looking for is the same on a user, something like user.AbandonSessions().

I realize this question has been asked before but I can't get a straight answer.

Thanks

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

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

发布评论

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

评论(3

心是晴朗的。 2024-09-17 16:04:01

我想你可能正在向风车倾斜。有太多的事情不利于你的预期目标。

如果您调整视角以接受基于浏览器的应用程序的任意性,而不是尝试消除用户状态的所有痕迹以避免错误,而是采取措施确保会话中存在所需的数据,如果没有然后重新创建它或将用户重定向到适当的位置。

无论如何,请记住,为了有效地影响任何与会话相关的操作,您必须强制请求周期以确保浏览器正确处理 cookie,但这不是我想要阐述的重点。

祝你好运。

I think you may be tilting at windmills. There are just too many things working against your desired goal.

If you adjust your perspective to embrace the arbitrary nature of a browser based app and instead of trying to eradicate all vestiges of a users state in order to avoid errors, rather take measures to ensure that the required data is present in the session and if not then recreate it or redirect the user to an appropriate location.

In any case, remember that in order to affect any session related action capably, you must force a request cycle to ensure the cookies are properly processed by the browser, but that is beside the point I am trying to make.

Good luck.

柠檬色的秋千 2024-09-17 16:04:01

您可以使用自定义会员资格提供商,它不会删除帐户,而只是停用该帐户。您还可以让自定义会员资格提供商同时锁定帐户。

You could use a custom membership provider which instead of deleting an account, just deactivates that. You could also have the custom membership provider to lock the account at the same time.

软糯酥胸 2024-09-17 16:04:01

FormsAuthentication.SignOut();

但您需要在要注销的用户的上下文中调用它。

FormsAuthentication.SignOut();

But you need to call it in the context of the user you want to sign out.

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