47

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.

0

8 Answers 8

85
  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>
12
  • 2
    This works but I note that you can't step into the dotnet core framework code or even see the real names of things in the callstack for the frameworks. If anybody finds some way to do that please update this answer.
    – Warren P
    Commented Jul 14, 2016 at 19:29
  • 1
    Any luck with this? I can't to get it to work? I published debug, and tried to attach in so many ways. It just won't hit my breakpoint.
    – code5
    Commented Nov 8, 2016 at 1:13
  • 1
    How do you publish an application with debug configuration? Commented Feb 3, 2017 at 15:50
  • 2
    Right click on the project, choose Publish, on settings tab choose Configuration that starts with word Debug
    – Vitaly
    Commented Feb 3, 2017 at 18:40
  • 1
    Thanks for the tip regarding attaching to the projectname.exe. It's just habit attaching to IISExpress.exe.
    – Jeff
    Commented Jun 8, 2017 at 23:16
10

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


2
7

The benefit is you can actually use the website outside using an actual hostname. Imagine having an android app trying to connect to localhost to debug an asp.net core web api service. a pain to setup unless you can actually use an actual physical ip address and connect to something running on iis. Just like BEFORE. Everything can be done but it doesn't mean if it's new it's automatically more practical. And not having the old debug iis option is a step backwards in terms of productivity.

2
  • My use case was I was writing an Alexa service which communicates to my box via https on 443.
    – Brandon F
    Commented Sep 9, 2016 at 17:52
  • I mean, useful discussion, but can you say how this answers the OP's question?
    – ruffin
    Commented Jun 16, 2021 at 14:02
6

Is this really necessary? ASP.NET Core applications run as an external process to IIS (using dotnet.exe) so there's really nothing gained by debugging through IIS. The backend application gets requests over plain HTTP.

For more info how the actual IIS hosting works with ASP.NET Core you might want to check out this blog post: http://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications-with-IIS

Visual Studio currently doesn't support debugging under full IIS and from what I've heard this is not something that is planned either. Microsoft does support running with IIS Express and you can set up a certificate for IIS Express.

In the ASP.NET Core project, in the Debug Project options there's an Enable SSL option that you can enable. IIS Express will create a local certificate and let you debug your application using SSL.

The benefit with this approach is that it just works by pressing F5 - no manual attachment required.

enter image description here

8
  • It enables "save/reload" scenarios for views without compiling, doesn't it? Commented Dec 9, 2016 at 23:54
  • 1
    Visual Studio does and always has supported debugging under full IIS. Commented Feb 3, 2017 at 14:44
  • What if i need to debug requests from other machines/devices? Does IIS Express handle remote connections?
    – Laserson
    Commented Jun 20, 2017 at 0:29
  • Bonner - but not ASP.NET Core debugging. Not like outlined by Vitaly using explicit process attachment to Kestrel. Lserson - IIS Express can be used for remote connections but you have to configure it to do so and open the firewall. For more info see this blog post: weblog.west-wind.com/posts/2016/Sep/28/… Commented Jun 20, 2017 at 2:10
  • 1
    The thing I miss the most with ASP .NET Core is not having to hit CTRL+F5 to run (or F5 to debug). You just build, navigate to localhost (or whatever binding you configured) and you run your code...
    – bounav
    Commented Nov 13, 2017 at 11:26
1

I tried all the above suggestions, but nothing worked until I put all the missing elements together.

The essential parts of debugging in IIS are:

  • Configuring IIS correctly on your dev. machine
  • Installing an SSL certificate for your IIS site
  • Adding Development Time IIS support from Visual Studio installer
  • Installing at least .NET Core SDK 2.2
  • Setting up your Launch Profile in Visual Studio to launch your browser using IIS.

.NET Core 2.2 is needed to run your site WITHIN the IIS process.

Here's more detail: http://intrinsicinnovation.com/Articles/2019/01/08/debugging-asp-net-core-applications-within-iis/

3
  • The link is a good one, but the answer probably needs more information from there to stand on its own. In case that link dies, similar steps are described at MS' docs here. "Development Time IIS support" is probably the key search phrase.
    – ruffin
    Commented Jun 16, 2021 at 14:13
  • Really poor answer here. You need to provide more detail. This is way too general. You probably should not have provided an answer.
    – Craig
    Commented Sep 5, 2022 at 16:45
  • Craig, really poor comment here. You probably should not have provided a useless comment.
    – Chris J
    Commented May 23, 2023 at 6:52
0

Just went through the history and stumbled upon this one. In case anyone every comes to this question...the solution for me turned out to be quite simple. If you're using authentication on your .net core app simply make sure it's using basic auth using HTTP(for the debug part). Then in IIS simply use Url Rewrite to setup a reverse proxy to your http://localhost:someport .net core instance. That's it. Problem solved. Perhaps url rewrite will support https soon and in that case the auth basic using HTTP can be used for debugging purposes as well. Which would be great. But so far this setup solved all my problems.

0

I was looking for a solution that would allow me to debug a .NET core sub-app, while running on a website that hosts Classic ASP code.

Looooooka's reverse proxy solution worked for me, but it took some work to figure it out.

1.) Add this line to Startup.cs.

app.UsePathBase("/core");  // core is the name of my subdirectory

Make sure you put it BEFORE the line that says "app.UseStaticFiles();"

2.) Install "URL Rewrite v2" and "Application Request Routing"

3.) Add a folder to the IIS website (/core) and create a web.config file inside the folder like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="IISExpressReverseProxy" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                    </conditions>
                    <action type="Rewrite" url="http://localhost:1306/core/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

4.) Open the project properties in visual studio, and go to the debug tab. Change the "Launch browser" url to your IIS url.

0

I had the same issue for an ASP.NET Core 2.2 Web API project that I wanted to run against IIS.

launchsettings.json

  "iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": true,
    "iis": {
      "applicationUrl": "http://localhost/AspNetCore22Starter",
      "sslPort": 443
    },

IIS

Configure https binding. Also it is recommended to define a specific application pool for the web application in order to make attach process easier to find

Attach to process

Attach to process (Ctrl-Alt-P) + find w3wp.exe process + pick the one that has User Name = IIS APPPOOL\:

Hosting process for ASP.NET Core 2.2 application

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.