Fix "Unable to Find Package" NuGet Error in Visual Studio C#
Overview
If you're a developer, you've probably heard of debuggers. The debugger in.net 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 asp.net and.net 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.
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, asp.net 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.
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 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)
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.
Used In This Tutorial:
Here, we will learn to debug the IIS-hosted web application in both Asp.Net and Asp.Net Core projects.
Here, I am creating one sample asp.net core project and named it "DebugIISHostedWebApplication" as shown below.
Fig: Sample asp.net core project
If you have successfully enabled the IIS service then you can move forward, otherwise, go here.
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
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.
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.
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.
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.
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 asp.net MVC
Integrating Vue JS with asp.net core