How to debug IIS hosted web application in visual studio ?

👤 Diwas Poudel    🕒 17 Nov 2021    📁 TECH


If you're a developer, you've probably heard of debuggers. The debugger is a built-in program in Visual Studio that aids in detecting and correcting errors in code. On the local system, the built-in IIS server serves as the default debug server for core projects. But what if we're hosting a web application in IIS? By attaching the worker process (w3wp.exe) of the intended web application to Visual Studio, we can easily debug any web application that is hosted on IIS.

What is IIS?

IIS stands for Internet Information Services, formerly known as Internet Information Server is a Windows Service that allows you to host(or store), manage, and test websites or web application on Windows Systems. You can host any sites like PHP websites, static websites, websites, java websites in IIS. So, IIS does all the processing and managing of your websites. You can host multiple applications in IIS.

         In Linux, you have heard about Apache Server, the same function that Apache Server does in Linux is done by IIS in windows System.

What is the w3wp.exe worker process?

All application runs under the worker process. When a client sent a request to the server, the worker process will be responsible for generating the request and response. So, we can claim that the worker process is one of the main functional parts of the ASP.Net Web application running on IIS.

For debugging web applications hosted on IIS, you much enable IIS at first.

Enabling IIS Step By Step (You can skip this if you have done it already)

    1. Press Win + R keyboard keys combination to open Run Window, then type appwiz.cpl and press Enter.appwizard
    2. Program and Features windows will open, on the left pane you will find the "Turn Windows features on or off” link. Click on it.windowsfeatureswindows
    3. Then Windows Features windows will open, there for simplicity, check all the subcomponents inside Internet Information Services. and press the Ok button. Then you may have to wait sometimes for applying Windows Features Changes.

Enable All Sub Component Inside IIS. For Simplicity Purpose

      4.) Next, go to browser and type: http://localhost and you must get this type of screen. This is the default page for IIS, indicating that IIS is successfully activated.check IIS is activate or not

Used In This Tutorial:

  •  Visual Studio 2019 
  •  IIS
  •  Visual Installer 

Here, we will learn to debug the IIS-hosted web application in both Asp.Net and Asp.Net Core projects.

Debug IIS Hosted Web Application in Asp.Net Core Project

1) Open/Create Sample Core Project.

 Here, I am creating one sample core project and named it "DebugIISHostedWebApplication" as shown below.

Fig: Sample core project


2) Add web application in IIS

If you have successfully enabled the IIS service then you can move forward, otherwise, go here.

   2 a) Open IIS

Click on the start button and type "IIS" in the search box and you will see the Internet Information Services(IIS) Manager at the top of the list. Then click on it.

fig. Open IIS


   2 b) Add Sites

Now, You will get Internet Information Services Windows. On the left side, you will find the "Sites" bar.Right-click on it and select "Add Website" as shown in the figure.

add website to iis

fig: Add Website 

   2 c) Give the name and set path of your project

       Then Add Website window appears. Here, you need to give all the details for your web application.

  1.  Enter the site name: You can give any name. Here, I have given debugTest. Remember that this is the name of the website in IIS.
  2.  Set Physical Path: Physical Path of the file where the site is located in the System.
  3. Click on the Ok button.

   sitename and physical path location

   2 c) Verify Your Site or Application in IIS

  After successfully completing the above steps, just go to your IIS, look at the sites section at the left pane, and then check there a website/application that you have added currently is present or not?

You can see that the name "debug test" is located there. Next just expand that sites and see whether there is content like shown above is present or not. If you don't have the content then you are doing something wrong. If so check it out.

 2 d) Browse your site or application  from IIS

Right-click on your project. Then click on "Manage Website". Then next click on "Browse". 

Now your sites should be opened in a web browser.

start project at iis

3) Enable Development-Time IIS support 

For enabling Development-Time IIS Support we must need a Visual Studio Installer.

 3 a ) Goto's bottom-left corner and type "visual studio installer" as shown below. Then click on "Visual Studio installer.".This will launch Visual Studio Installer.

 3 b) Visual Studio Installer gets open as shown before.

  Select the Development time IIS support component and this is present in the Optional section under the ASP.NET and web development workload. The component installs the ASP.NET Core Module, which is needed in order to run .net core apps on IIS.


Now, we can finally debug the application in Visual Studio.


4)Attach w3process in Visual Studio

   4a) Open your Project in Visual Studio and attach debug point 

Open visual studio and attach debug points somewhere in the project as shown below.


Then build the project (shortcut: Ctrl + Shift + B ).

  4b) Next, attach a process 

In Visual Studio, go to Debug → Attach to Processor simply press Ctrl + Alt + P Key combination

After clicking Attach to Process, this screen will come up.

There check on "Show process from all users". Click on the "Refresh" Button then go and find the w3wp.exe process as shown below. And next click on "Attach" Button

Then look at the debug point and you must have debugged point looks as shown on the left which indicates that the Process attached successfully.

Now, hit your debug point from the browser. Then your debug point should look as shown below:

So we have successfully debugged IIS Hosted web application.


Related Post 

Integrating PostgreSQL with MVC

Integrating Vue JS with core

A - Z | Microsoft Technology Stack

Importing and Exporting Postgresql file