ASP.net:如何列出 Web 应用程序所有用户会话
我想知道我的网站内存使用情况,首先我想知道所有用户的Session详细信息,这将帮助我决定是否将sessionState模式更改为“SqlServer”或“StateServer”。
我该怎么办?
谢谢
I want to know my website memory usage,first i want to know Session detail of all users,this will help me decide whether to change sessionState Mode to "SqlServer" or "StateServer".
How can i do?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于网站内存使用情况,我会查看 perfmon。如果我真的想计算每个用户会话中使用了多少内存,我会在添加时进行计数,而不是在放弃会话时进行计数。如果你到处都有 Session["foo"]=bar ,这可能会很棘手,它需要以某种方式包装起来。
如果您确实更改为进程外会话状态,则需要测试涉及会话的所有内容。您的会话变量跨越了进程边界,它们需要可序列化,并且肯定有一些东西不起作用。
For website memory usage, I would look at perfmon. If I really wanted to count how much memory I was using in each user session, I would do that count when adding not when abandoning the session. This could be tricky if you've got Session["foo"]=bar all over the place, it needs to be wrapped up somehow.
If you do change to out of process session state, you will need to test everything that touches the session. Your session variables are crossing process boundaries, they need to be serializable and there are definitely some things that don't work.
我不确定这是否会帮助您解决问题,但您可以在 Session_End 事件中尝试这段代码...假设该事件是从您的注销过程中触发的。
这是会话变量可用的最后一个事件。
this.Session.Count 应该为您提供应用程序服务器中的会话数。仅当您的应用程序托管在单个 Web 服务器而不是 Web 服务器场中时,此解决方案才可能有效。我不知道 Web 服务器场中如何处理会话。
I am not sure if this will help you solve the problem but you can try this piece of code in Session_End event... Assuming that this event is fired from your logout process..
This is the last of the events where Session Variable is available.
this.Session.Count should give you the number of sessions in the server for the application. This solution may hold good only if your application is hosted in single web server and not on a web server farm. I am ignorant of how sessions are handled in a web server farm.