问题
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