Debug your ASP. Application while Hosted on IIS

Source: Internet
Author: User

Turn: Http://www.codeproject.com/Articles/37182/Debug-your-ASP-NET-Application-while-Hosted-on-IIS

This article describes how to debug a Web application which are hosted on IIS. It also describes how to select the correct process to attach to when multiple worker processes is runningcontents
    • Overview
    • ASP. Debugging vs. IIS debugging
    • What is the Worker Process?
    • Application Pool
      • What is Application Pool?
      • Default Application Pool
      • Creating and assigning an application Pool
      • Assign Site to the application Pool
    • How to start?
    • Which process to attach?
    • How to attach to one of many running Worker Processes
      • Getting a list of running Worker Processes
      • Attaching to the correct process
    • Summary
Overview

Generally we debug our ASP. NET Web application from Visual Studio. Visual Studio has its own ASP. NET engine, which is capable enough to run and debug your Web sites inside Visual Studio. However, if your site is hosted on IIS and you want to debug this site directly, how would do you debug it? When we host sites on IIS, the Worker Process (w3wp.exe) was used to run the Web application. We need to attach-particular process from Visual Studio to debug the Web application. This article describes the overall idea of debugging a application using this method. It also describes the Worker process, application Pool and selecting a particular process if there are M Ultiple Worker Processes running on IIS, using iisapp.vbs . I hope you'll enjoy this article and provide your valuable suggestions and feedback.

ASP. Debugging vs. IIS debugging

Visual Studio has it own integrated debugging engine, which debugs our code when we run the application in Visual Studio. If We are developing a site and need to debug the code, we just set breakpoints and does the debugging (note: in t His article I does not describe how to set the Debug mode).

When we run the application, execution breaks when certain a breakpoint is reached. It's very simple, because if an ASP. Application is running in Visual Studio, it's under the control of the ASP . NET Engine which is integrated with Visual Studio. If you want to check which process was running for debugging, run the Web application from Visual studio:you would get a PO PUP notification as shown below.

Fig. 1:taskbar Popup When debugging was started from Visual Studio

This indicates a process was starting to run the ASP. Application. Double-click on the icon and a popup window would appear to show the details.

Fig. 2:development Server Process Details

Behind The running process is WebDev.WebServer.exe. When We press F5 to run the application, this process starts to execute the IT. If you want run of the application from command prompt, you had to perform the following steps.

Steps to run a Web application from the command prompt:
    1. Open the Visual Studio command prompt
    2. Run Webdev.webserver

The following screen would come up. Check the Example section there.

Fig. 3:WEBDEV.WEBSERVER Usage Notification

Now the back to IIS debugging. IIS comes into the picture when we deploy or host the site. After deploying the site on IIS, if we want to debug the site there, we can ' t do it directly as in Visual Studio. IIS has it own   Worker Process which takes care of all execution and maintenance of deployed Web applications . I'll describe the details of the Worker Process in a later section. So, if we had running process in IIS and we need to debug the application, first of all we had to attach to the correct Process from Visual Studio. Before describing that, let's just has a look at the Worker Process and application Pool.

What is the Worker Process?

The Worker Process (w3wp.exe) runs ASP. Applications within IIS. All ASP. Functionality runs under the scope of the Worker Process. When a request comes to the server from a client, the Worker Process was responsible for generating the request and respons E. Its also maintains the InProc session data. If we recycle the Worker Process, we'll lose it state. For more information, read this article:a low-level look at the ASP. Architecture

Application Pool

This is one of the most important things, should create for your own application in a production environment. Application pools is used to separate sets of IIS Worker Processes that share the same configuration. Application pools enable us to isolate we web application for better security, reliability, and availability. The worker process serves as the process boundary that separates each application Pool, so if one Worker process or Application has a issue or recycles, other applications or Worker Processes is not affected.

Fig. 4:relationship between application pool and worker process in Iisdefault application pool

The name of the default application of IIS 6.0 is DefaultAppPool. After hosting the site in IIS, if we check the properties of the virtual directory, we can to view that information as fol Lows.

    1. Start menu→ Run command→inetmgr
    2. Expand defaultwebsites or other Web Sites, where you have created the virtual directory
    3. Right Click on the virtual directory
    4. Click on Properties

The following virtual directory Properties screen would come up, showing the application Pool name which are assigned to the Selected site.

Fig. 5:virtual Directory properties showing application Pool name

If you want to check the list of all application pools in IIS and you have to expand the application Pool node on II S Server.

Fig. 6:list of application Pools

Now, each and every application Pool should has the minimum of one Worker Process which takes care of the operation of th e site which is associated with the application Pool. Right-click on the application Pool→go to the Performance tab, check in the bottom of the tab, there is a web Garden sections, and by default, the number of Worker Processes is 1. An application Pool containing more than one Worker Process called a Webgarden.

Fig. 7:application Pool Properties showing Web GardenCreating and assigning an application Pool
    • Open The IIS Console, right-click on the Application Pools folder, select New

      Fig. 8-1

    • Give the application Pool ID and click OK.

      Fig. 8-2

    • Now, right-click in the virtual directory and assign the newly created application Pool to that virtual directory.

      Fig. 8-3

Now, this web site would run independently, within Stateserverapppool, so any problem related to other application s won't affect this application. This is the main advantage of creating a separate application Pool.

How to start?

What I had said up to now give you a good idea of Worker Processes and application pools. You should has a clear understanding on these before going on to the next part. Now I'll show you how to debug a site which was hosted on an IIS Server.

For the demonstration, I had created a web site called samplewebsite and hosted it on to my local IIS. Below is default page output.

Fig. 9:sample Web site which process to attach?

Now, as I has already explained, the process name is w3wp.exe, so we can check it from our Task Manager whether Or not, the Worker Process is running.

Fig. 10:task Manager showing the running IIS process

Now we is going to attach to the process. In Visual Studio, go-to- DebugAttach to Process

Fig. 11:opening the Attach to ProcessWindow

After clicking Attach to Process, the following screen would come up

Fig. 12: Attach to Processwindow, showing a single Worker Process running

Now we were able to see that the Worker process was running, and we need to attach that process. Select the process and click on the Attach button. After this, look at the images below:

Fig. 13-1: Process attached successfully

Fig. 13-2: Process not attached

Did you notice the breakpoint symbol? If the Worker Process attached successfully, within the code, the breakpoint symbol should be a solid circle. Otherwise it would have a warning icon as shown. For a single Worker Process, this scenario is not common. However, when we had multiple Worker Processes running on IIS, then we can have some confusion. I'll discuss the same in a later section.

Now if we click the Debug button After successfully attaching to the process, execution'll stop at the Breakpoi Nt.

Next, let's has a look at-what-if we have multiple Worker Processes running.

How to attach to one of many running Worker Processes

Now, when is this scenario would come up? When we had multiple sites hosted on IIS, and those sites had their own application Pool. Now, multiple application pools means multiple Worker Processes is running.

Here I has three application pools in my IIS. They is:

    1. Default Application Pool
    2. Generic Application Pool
    3. State Server Application Pool

Now, my samplewebsite are associated with the DefaultAppPool. Now, I want to attach the process to debug mysamplewebsite. Follow the same steps as before. Open the Process Attach window:

Fig. 14:list of multiple Worker Process

Just had a look, there is three Worker Processes currently running, and you had to attach one of them. But know which Worker Process is the default application Pool ' s. What do are, you select any one of them at random, let's say the one with process ID = 4308 and Suppose it's not t He Worker Process for the default application Pool. So what would happen if you attach to a wrong process? Check the image below:

Fig. 15:breakpoint when the process was not attached correctly Getting A list of running Worker Processes

What's the solution for the previous case? Here is a quick tip:

    • Start →run command→ cmd
    • Change directory to \Windows\System32
    • Run the command:cscript iisapp.vbs

And wait for the output. wow! You get a list of running Worker process, process ID and application Pool Name!

Fig. 16:list of running Worker Processes with PID and application Pool name attaching to the correct process

From this can easily identify the correct application Pool name and its process ID. Now, return to Visual Studio→attach Process. Now you know this process ID for Default application Pool 1772 are, so Attach to that process.

Fig. 17:attach the correct process for debugging

Now, enjoy debugging!

Fig. 18:breakpoint is Readysummary

Sometimes we need to debug our application which are hosted on IIS. For this, we need to attach the running Worker Process to the Visual Studio. If We have multiple worker Processes running on the IIS server, we can identify the appropriate Worker Process by using th e command cscript iisapp.vbs .

I hope this article would help beginners who is still struggling with debugging applications that is hosted on IIS. Give your feedback and suggestions to improve the article.

Thank.

License

This article, along with any associated source code and files, is licensed under the Code Project Open License (Cpol)

Debug your ASP. Application while Hosted on IIS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.