Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging ASP.NET Core applications running in IIS

Is there any way to debug an ASP.NET Core web application while running under IIS?

I'm running under IIS because I need it to be available over SSL on port 443.

like image 367
Brandon F Avatar asked Mar 29 '16 22:03

Brandon F


People also ask

How do I debug the .NET core app?

Open the Debug view by selecting the Debugging icon on the left side menu. Select the green arrow at the top of the pane, next to . NET Core Launch (console). Other ways to start the program in debugging mode are by pressing F5 or choosing Run > Start Debugging from the menu.

Can ASP.NET Core run on IIS?

NET Core Library, and the ASP.NET Core Module. The module allows ASP.NET Core apps to run behind IIS. If the Hosting Bundle is installed before IIS, the bundle installation must be repaired. Run the Hosting Bundle installer again after installing IIS.


2 Answers

  1. Publish web application with Debug configuration
  2. Set up web site on IIS as described here
  3. Open web site in browser to have dotnet process started
  4. In Visual Studio open Debug -> Attach to Process or press Ctrl+Alt+P
  5. Make sure in "Attach to" line you have "Automatic" or "Managed (v4.6, v4.5, v4.0)". If not, press select and choose "Automatically determine the type of code to debug"
  6. Check "Show processes from all users"
  7. Select dotnet.exe and press Attach

Note: If you see several dnx.exe processes, choose the one with IIS user in column username. By default it is "IIS APPPOOL{your app pool name}"

P.S. If you see dotnet process with empty username, run Visual studio as Administrator

UPDATE

With ASP.Net Core 1.0.0 you must attach to "{youprojectnamet.exe}". E.g. if you project has name "Web", you must attach to "Web.exe" Also you can find name of the executive in the following section of web.config

<system.webServer>    <aspNetCore processPath=".\Web.exe" /> </system.webServer> 
like image 138
Vitaly Avatar answered Sep 19 '22 04:09

Vitaly


Scenario : Debugging ASP.NET Core Web Application running on IIS Local.

Prerequisite: Add "Development time IIS support" to your existing Visual Studio installation. Follow the next link: https://blogs.msdn.microsoft.com/webdev/2017/07/13/development-time-iis-support-for-asp-net-core-applications/


1. In Visual Studio 2017 create "ASP.NET Core Web Application" with name "MvcMovie".

1.1. Open "MvcMovie" project Properties.

1.1.2. Go to "Debug" tab and set(if not):

1.1.2.1. "Profile:" "MvcMovie".

1.1.2.2. "Launch:" "IIS"

1.1.2.3. (checked)"Launch browser:" "https://localhost"

1.1.2.4. "Environment variables:" | Name: "ASPNETCORE_ENVIRONMENT" | Value: "Development" |

1.1.2.5. "Web Server Settings"

1.1.2.5.1. "App URL:" "https://localhost"

1.1.2.5.2. (checked)"Enable Anonymous Authentication"

enter image description here


2. In "IIS Local" manager "Add Website" with name "AspNetCoreMvcMovie".

2.1. Set "Physical path" with the project(NOT the solution) folder(in our case "D:\ASP-NET-Core\ASP-NET-Core-Projects\MvcMovie\MvcMovie").

2.2. Binding "Type" : "https".

2.3. "SSL certificate" : "IIS Express Development Certificate".

2.4. Click "OK".

2.5. Into "Application Pools" find by name "AspNetCoreMvcMovie" pool.

2.5.1. Into "Edit Application Pool" set ".NET CLR version" to "No Managed Code".

2.5.2. Click "OK".

enter image description here


3. Set VS 2017 elevated permissions.

3.1. If we have massage like that: "Microsoft Visual Studio": "This task requires the application to have elevated permissions", follow troubleshooting "(Method 2) Troubleshoot Compatibility" in next link: https://social.technet.microsoft.com/wiki/contents/articles/46441.visual-studio-2017-this-task-requires-the-application-to-have-elevated-permissions.aspx

3.2 After accomplishment of this method(Method 2), VS-2017 will start.

3.3. Run(in "Debug" mode) "MvcMovie" application with IIS-profile(which is set to run on IIS Local... !!! NOT the IIS Express !!!). In our case profile is set with name of the current application("MvcMovie") in "Step 1.".

3.4. Wait application to run in browser.

3.5. Close application(close web-browser).

3.6. Go to compatibility-troubleshooting-window and click "Next".

3.6.1. Then click on "-> Yes, save these settings for this program".

3.6.2. After "Resolving issues" finishes "Saving settings", we have to view window "Troubleshooting has completed". In the window "Troubleshooting has completed", have to view : "Issues found" -> "Incompatible Program" -> "Fixed". Then click on "-> Close the troubleshooter".

4. From VS-2017, Run(in "Debug" mode) again "MvcMovie" application with IIS-profile(in our case with name "MvcMovie").

enter image description here


like image 42
Ted Avatar answered Sep 18 '22 04:09

Ted