ASP.NET MVC 5 debugging with IIS Express

Answered

I was trying to setup debugging for a solution with two ASP.NET projects, one is am MVC 5 project, the other a WebApi 2 project. There is also a third shared library. What I am trying to achieve is a similar behavior as in Visual Studio, where a single click would fire both the API project and the Web project in IIS Express with the debugger attached, and start a browser with both sites as tabs.

I managed to get pretty far. I created two build configs for .NET executables setup to spawn the iisexpress.exe process with the right path and port for the sites. I also chose to create a third config to start chrome and pass in the two urls. Finally, I've added a compound config to fire up all build configs. This works fine for running the site, but I cannot figure out how to attach the debugger.

It seems that compound configs cannot start with a debugger attached. Am I right?

Even so, just starting one of the two sites in debug mode does not trigger any breakpoints. By looking at the csproj files, in those projects, there seems to be a special parameter that needs to be passed to correctly debug iisexpress sites. This parameter is not documented in the command-line interface for iisexpress.

Is there any possible way to get this working without depending on an explicit support from Rider in the form of a new ".NET IIS Express project" build configuration?

0
6 comments

similar question to me, how can i debug a web api 2 project which run in iis.

i tried to spawn w3wp.exe but nothing happened.

0

Unfortunately this feature is not ready yet in Rider, but you can run debug with IIS Express against ".Net Executable" run configuration.
Set up parameters:
- Exe path: C:\Program Files\IIS Express\iisexpress.exe or C:\Program Files (x86)\IIS Express\iisexpress.exe
- Working directory: your project home folder
- Arguments:
- for vs2015 /config:{SOLUTION_FOLDER}\.vs\config\applicationhost.config /site:{ProjectName} /apppool:Clr4IntegratedAppPool
- for vs2013 /config:{MY_DOCUMENTS_FOLDER}\IISExpress\config\applicationhost.config /site:{ProjectName} /apppool:Clr4IntegratedAppPool
NOTE: For now please make sure that you don't have any 'spaces' in {Project Path}. Sorry for any inconveniences.
We will try to add run configurations for WebApp in next EAP. Let us know if it helps you. By the way, feel free to provide us with any kind of feedback.

1

EDIT: It turns out I finally managed to get this working!

The key is to use the x86 version of IIS Express. I noticed this because the x64 version would not show up in the "Attach to .NET process" window.

Here is my final configuration. I have 4 build configurations. All are .Net Executables:

1. Build - Exec path: C:\Windows\System32\cmd.exe - This config exists only to trigger a build for the solution
2. Start Api - Exec path: C:\Program Files (x86)\IIS Express\iisexpress.exe - Nothing in "Before launch". The rest is setup according to Mikhail's post.
3. Start Web - Same as "Start Api" but for a second project.
4. Open in Chrome - Exec path: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe - Arguments: http://localhost:{API PORT NUMBER}/swagger http://localhost:{WEB PORT NUMBER}/

I also added a compound build configuration called "Start" which runs all other 4 configurations. Unfortunately, this is necessary because since IIS Express is an on going process, trying to chain the configurations by adding them in the "Before launch" section will simply cause them to stop after the first instance of IIS Express is started.

0

I was unable to get the debugging working for my WebApi project. I'm using the x86 version of IISExpress for a ".NET Executable" configuration and can successfully get data via Postman, but no breakpoints are hit in my controller. I also get the message "The breakpoint could not yet be bound to a valid location" in my controller. The only non-standard part of my solution is that the WebApi project name is different than the actual site name used in IISExpress argument. 

1

In version 2019.3.1 this still happens.
Is there another way around this problem?

0

Hello, Hellington.

Could you please clarify, which scenario doesn't work for you? IIS Express debugging is fully supported and is expected to work for both classic ASP.NET projects and ASP.NET Core projects (only out-of-process hosting for now).

0

Please sign in to leave a comment.