如何清除 ASP.NET 中所有用户的 SQL 会话状态
我使用 SQLServer SessionState 模式在 ASP.NET 应用程序中存储会话。它存储每次使用时序列化/反序列化的某些对象。
如果我对这些对象的结构的代码进行任何更改,并且启用新版本,则任何登录的用户都会收到错误,因为他们的会话对象(旧版本的)与新版本期望的结构不匹配,而反序列化。
有没有办法一次性清除数据库中的所有会话,以便所有活动会话过期并且用户被迫再次登录(因此所有会话对象都是从头开始创建的)?
或者……有没有其他办法可以解决这种情况?
I use SQLServer SessionState mode to store session in my ASP.NET application. It stores certain objects that are serialized/deserialized every time they are used.
If I make any changes in code of the structure of those objects and I put a new version live, any logged user will get an error, as their session objects (the old version ones) do not match the structure that the new version expects while deserializing.
Is there a way to clear all sessions at once in DB so that all active sessions expire and users are forced to log in again (and therefore all session objects are created from scratch)?
Or... Is there any other way to solve this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用SQL Server中的存储过程来清除所有会话:
You may try using stored procedure in SQL Server to clear all the sessions:
当每个用户遇到无效的 Session 对象时,您可以为每个用户调用 Session.Abandon 或 Clear。
您还可以循环遍历每个用户的 Session 集合,并清除可能包含“旧”对象的键。也许您有一张登录票并且不想清除。
You can call Session.Abandon, or Clear for every user when they hit the invalid Session object.
You can also loop through the per-user Session collection, and clear the keys that can contain "old" objects. Maybe you have a login ticket and such that you don't want to clear.