如何查看所有活动会话的会话状态中的所有内容?
我想创建一个管理页面来表明我们对会话状态的使用并没有失控。
是否可以检索所有活动会话的列表,如果可以,如何访问每个会话中的所有会话数据?
I'd like to create an administrative page to show that our use of session state isn't getting out of hand.
Is it possible to retrieve a list of all active sessions, and if so, how can I access all of the session data in each session?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
免责声明:我只是想出了这个实现,因为我认为这是一个有趣且可以解决的问题。因此,可能有一些问题或细节我忽略了考虑。不过,如果您使用 InProc 会话状态,这里有一个解决方案。
摘要:创建一个应用程序级对象(例如列表),存储在
Application_Start
事件期间创建的应用程序状态中,并在每个Session_Start
事件上添加对会话的引用到您的清单。在Session_End
上,将其删除。要检索所有活动会话和值,请循环遍历会话列表,然后遍历每个会话的密钥。Global.asax
SomePage.aspx
输出:(加载第二个浏览器访问该页面后)
Disclaimer: I just came up with this implementation because I thought this was an interesting - and solvable - problem. As such, there may be some issues or details I've neglected to consider. Nevertheless, if you are using InProc session state, here's a solution.
Summary: Create an Application-level object (eg. a List) stored in Application state created during the
Application_Start
event, and on eachSession_Start
event, add a reference to the session to your list. OnSession_End
, remove it. To retrieve all the active sessions and values, loop through your list of sessions, then through the session keys of each.Global.asax
SomePage.aspx
Output: (after loading up a second browser to hit the page)
无法从另一个会话访问会话。然而,通过实现会员资格提供程序,您可以知道会话是否处于活动状态以及有关用户活动的许多其他有用信息。此外,通过使用数据库保存会话状态,您可以检索所需的信息。
您可以使用“活动”标志来存储/删除数据库中的会话,以获得更具可扩展性的解决方案,以防这对您很重要。
Session's cant be accessed from another session. However by implementing membership provider you could know if a session is active and many other useful information about user's activities. Also by persisting the session state using a DB you could retrieve the information you want.
You could use an "active" flag to store/remove sessions in the db just to obtain a more scalable solution, in case that's important for you.