Find Process Id of an IIS Site by Site Name

To find process Id of the worker process which is serving an IIS application, you can simply use Internet Information Service (IIS) Manager console. To do so, first make sure the worker process of the application is running (by browsing the application) then:

  1. Go to IIS manager and click on server node.
  2. In feature view, open Worker Processes.
  3. You can see the worker processes and related information including Process Id:


But how to do it using C# code?

Here is what I’ve tried to get process Id of a web site using code:

//using Microsoft.Web.Administration;
var server = new ServerManager();
var site = server.Sites.Where(x => x.Name == "mysite.local").FirstOrDefault();
var application = site.Applications.Where(x => x.Path == "/").FirstOrDefault(); ;
var applicationPoolName = application.ApplicationPoolName;
var processId = server.WorkerProcesses
    .Where(x => x.AppPoolName== applicationPoolName)
    .Select(x => x.ProcessId).FirstOrDefault();

To make it working, don’t forget to add Microsoft.Web.Administration reference. Also you should run the application or Visual Studio by “Run as Administrator”.

You May Also Like

About the Author: Reza Aghaei

I’ve been a .NET developer since 2004. During these years, as a developer, technical lead and architect, I’ve helped organizations and development teams in design and development of different kind of applications including LOB applications, Web and Windows application frameworks and RAD tools. As a teacher and mentor, I’ve trained tens of developers in C#, ASP.NET MVC and Windows Forms. As an interviewer I’ve helped organizations to assess and hire tens of qualified developers. I really enjoy learning new things, problem solving, knowledge sharing and helping other developers. I'm usually active in .NET related tags in stackoverflow to answer community questions. I also share technical blog posts in my blog as well as sharing sample codes in GitHub.

Leave a Reply

Your email address will not be published. Required fields are marked *