How to debug IIS hosted asp.net web application in visual studio ?


👤 Diwas Poudel    🕒 Jan 2 2020    📁 Fix    📜 0 comment

Overview

If you are a developer you have probably heard about debugger. The debugger in .net is the inbuilt program of visual studio which helps in detecting and correcting the presence of the errors in the code. In the local system, built-in IIS acts as a default debug server for asp.net and .net core project. But what to do if we are hosting a web application in IIS?💡 We can easily debug any web application that is hosted on IIS by attaching the worker process(w3wp.exe) of the intended web application to Visual Studio.

What is IIS?

IIS stands for Internet Information Services, formerly known as Internet Information Server is a Windows Service which 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, asp.net websites, java websites in IIS. So, IIS does all the processing and managing 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 asp.net 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 ASP.Net Web application running on IIS.

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

Enabling IIS Step By Step (You can skip this if you have done 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 "Turn Windows features on or off” link. Click on it.windowsfeatureswindows
    3. Then Windows Features windows will open, there for simplicity, check all the subcomponent inside Internet Information Services.and press 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

 

 

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 Asp.net Core Project.

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

Fig: Sample asp.net core project

 

2) Add web application in IIS

If you have successfully enabled 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 Internet Information Services(IIS) Manager at  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 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.