如何在asp.net中销毁当前用户以外的其他用户的会话
我将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想你可能正在向风车倾斜。有太多的事情不利于你的预期目标。
如果您调整视角以接受基于浏览器的应用程序的任意性,而不是尝试消除用户状态的所有痕迹以避免错误,而是采取措施确保会话中存在所需的数据,如果没有然后重新创建它或将用户重定向到适当的位置。
无论如何,请记住,为了有效地影响任何与会话相关的操作,您必须强制请求周期以确保浏览器正确处理 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.
您可以使用自定义会员资格提供商,它不会删除帐户,而只是停用该帐户。您还可以让自定义会员资格提供商同时锁定帐户。
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.
FormsAuthentication.SignOut();
但您需要在要注销的用户的上下文中调用它。
FormsAuthentication.SignOut();
But you need to call it in the context of the user you want to sign out.