How to get the current list of Worker Request from IIS using C#?

て烟熏妆下的殇ゞ 提交于 2019-12-06 08:22:11

问题


I am writing the code for a RESTful web service status page. I was wondering if there is away to get the current request from IIS into C#.

I am using IIS 7.0 and the info I want is under

IIS > Worker procecces > ASP.NET v4.0 > Requests


回答1:


You can use the GetRequests method of the WorkerProcess type. This type is located in the Microsoft.Web.Administration assembly which can be installed using this unofficial nuget package or by adding a reference to this dll %WinDir%\System32\InetSrv\Microsoft.Web.Administration.dll

Exemple :

using (ServerManager manager = new ServerManager())
{
    while (true)
    {
        var requests = manager.ApplicationPools
                                .Where(pool => pool.Name == "FooPool")
                                .SelectMany(pool => pool.WorkerProcesses)
                                .SelectMany(wp => wp.GetRequests(10));

        Console.WriteLine(requests.Count());
        Thread.Sleep(100);
    }
}


来源:https://stackoverflow.com/questions/30868022/how-to-get-the-current-list-of-worker-request-from-iis-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!