如何在ASP.NET中获取会话状态对象的集合?(How do I get a collection of Session State objects in ASP.NET?)
如何获取ASP.NET中所有Session对象的集合? (请注意,我不是要查找存储在Session对象中的对象集合,而是查找所有会话对象本身。)
这是针对将列出所有活动会话的管理页面,如果用户已登录,还将列出用户名等。
语言:C#框架:ASP.NET MVC 1.0(3.5 SP1)
编辑:到目前为止,有一些很好的答案,我想到的解决方案,但在我的原始问题中未提及,即在session_onStart和session_onEnd中添加和删除会话对象。 我还没有这样做的原因是我发现很难相信会话对象的集合不会暴露给我们。 我猜测ASP.NET将这个Session异常集合存储在某种类型的集合中,所以我试图找出如何获取该集合。 我很乐意编写额外的代码来自己管理它,但如果这个功能已经存在,我不是创建额外开销和代码来维护的粉丝。
How do I get the collection of all Session objects in ASP.NET? (Note that I am NOT looking for a collection of objects stored in the Session object but all of the session objects themselves.)
This is for an admin page that will list all active sessions and if the user is logged in will also list the user name etc.
Language: C# Framework: ASP.NET MVC 1.0 (3.5 SP1)
EDIT: A couple of good answers so far with a solution that I had thought of but not mentioned in my original question which is to add and remove the session objects in session_onStart and session_onEnd. The reason that I haven't done this yet is that I find it hard to believe that the collection of Session objects is not exposed to us. I am guessing that ASP.NET stores this collection of Session objections in a collection of some type so I'm trying to find out how to get hold of that collection. I am happy to write the extra code to manage it myself but am not a fan of creating extra overhead and code to maintain if this functionality already exists.
原文:https://stackoverflow.com/questions/1820246