简体   繁体   中英

How do I get a collection of Session State objects in ASP.NET?

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.

you can use global asax and following methods.

sub session_onStart() 

    application.lock() 
    // your logic
    application.unlock() 

end sub 

sub session_onEnd() 

    application.lock() 
// your logic
    application.unlock() 

end sub 

您可以使用global.asax文件并向Session_OnStart事件添加一些自定义代码,您可以获取用户信息并在可以提供管理页面的数据库中进行更新。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM