如何获取属于特定会话的进程?

发布于 2024-10-06 10:47:53 字数 318 浏览 1 评论 0原文

我想获取针对特定会话的所有进程。 即,如果有两个人正在使用我的 Web 应用程序,那么我想获取 user1 使用的所有进程和 user2 使用的所有进程。

I can get all processes by writing Process.GetProcesses() but how to get it in a group.
e.g:

User1:  Process342
User1:  Process151
User2:  Process452
User2:  Process674
User2:  Process111

任何人都可以帮忙吗?

I want to get all the processes that is meant for a particular session.
i.e if there are two persons who are using my web application then i want to get all the processes used by user1 and all the processes used by user2.

I can get all processes by writing Process.GetProcesses() but how to get it in a group.
e.g:

User1:  Process342
User1:  Process151
User2:  Process452
User2:  Process674
User2:  Process111

Can anyone please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

[旋木] 2024-10-13 10:47:53

我看到两种简单的方法可以在 C# 中执行您想要的操作(不了解 ASP.NET):

您可以按 SessionId 过滤进程以使进程为单个会话运行

Process[] processes = Process.GetProcesses().Where(p => p.SessionId == sessionID).ToArray();

或者您可以对结果进行排序以按会话对它们进行分组

Process[] processes = Process.GetProcesses().OrderByDescending(p => p.SessionId);

I see two simple ways to do what you want in C# (don't know about ASP.NET):

You could filter the Processes by SessionId to get the processes running for a single session

Process[] processes = Process.GetProcesses().Where(p => p.SessionId == sessionID).ToArray();

Or you could sort the results to group them by session

Process[] processes = Process.GetProcesses().OrderByDescending(p => p.SessionId);
笑忘罢 2024-10-13 10:47:53

您需要了解 ASP.NET 和 ASP.NET 是如何实现的。 IIS 协同工作 - 这些文章可能会有所帮助:

  1. http://www.code-magazine。 com/Article.aspx?quickid=0511061
  2. http://dotnetslackers.com/articles/ iis/ASPNETInternalsIISAndTheProcessModel.aspx
  3. http://msdn .microsoft.com/hi-in/magazine/cc188942(en-us).aspx

现在回到您的具体问题,ASP.NET 运行时托管在 IIS 工作进程中。 Session 只是一个从浏览器识别用户会话的逻辑范围,ASP.NET 提供了一个状态包来存储会话特定值。所有用户(会话)都由相同(一组)工作进程提供服务 - 因此查找每个会话的进程没有任何意义。您所能做的就是找出 Web 服务器上执行的进程。

You need to understand how ASP.NET & IIS works together - these articles may help:

  1. http://www.code-magazine.com/Article.aspx?quickid=0511061
  2. http://dotnetslackers.com/articles/iis/ASPNETInternalsIISAndTheProcessModel.aspx
  3. http://msdn.microsoft.com/hi-in/magazine/cc188942(en-us).aspx

Now coming to your specific question, ASP.NET runtime gets hosted in IIS worker process. Session is just a logical scope to identify user session from browser and ASP.NET provides a state bag to store session specific values. All users (sessions) get served by same (set of) worker process(es) - so finding processes per session does not make any sense. All you can do is to find out processes executing on the web server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文