Jeff
Jeff

Reputation: 12183

Debugging ASP.NET MVC3 application hosted on Local IIS Webserver

I've managed to use the local IIS Webserver to host my MVC3 application, and I can debug it and everything, from the machine that is hosting it. - however, when I send a request from another machine (my Mac, which is running my Windows in a Parallels VM), I get the expected result, but the debugger wont stop at my breakpoints!

I tried adding a Debugger.Break(); to my action, and that crashes the w3wp.exe ..

To, so summarize: Local requests are working, and can be debugged. External requests are working, but they cannot be debugged.

In my project's properties, I set the Use Local IIS Webserver, Use IIS Express is unchecked.

I'm using Visual Studio 2012 Professional. The project is Azure SDK-based, and the attached process is WaIISHost.exe.

Upvotes: 3

Views: 9862

Answers (4)

Jeff
Jeff

Reputation: 12183

The issue was that since I had set up my IIS server to serve on port 83, while locally I would access on port 81, the debugger would not monitor those requests.

To solve this (or, generally, to debug remotely on the Cassini Web Server), download a tool called rinetd, which is a very simple traffic redirector daemon, and create a config.cfg in the folder where you extracted it to. The format is <source ip> <source port> <dest. ip> <dest port>. So, on my Mac, I go to this address in Safari: 192.168.1.23:8080/Controller/Action , and that is then redirected to localhost:81/Controller/Action , as if it was a local request! Here is the example config.cfg:

192.168.1.23 8080 127.0.0.1 81

Alternatively, you can use your PC name, to avoid having to assign a static IP or change the config when DHCP gives you a new address:

Jeff-PC 8080 127.0.0.1 81

Then, open a command prompt, and cd to your rinetd folder, and run rinetd.exe -c config.cfg.

Works like a charm.

Upvotes: 10

Saw
Saw

Reputation: 6426

I can see that the remote requests are served by IIS, but the local ones are served via "Cassini" server or the server of visual studio.

Make sure that you are using IIS to debug your code, You can attache visual studio to w3wp.exe to debug via IIS. and you should start visual studio as Administrator.

To attache Visual studio to w3wp.exe (IIS process): From visual studio, from the debug menu select "Attach to process..." :

  • Check "Show processes from all users".

  • Check "Show processes in all sessions".

  • Choose "Managed (v....) code" from (Attach to.) by pressing select button.

  • Press "Refresh" button

w3wp.exe should be shown!

enter image description here

Upvotes: 7

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26737

You are probably attaching the wrong process.

Try to do the below to confirm you are debugging the wrong process.

  • From your local machine start the web application in debug mode (press F5).
  • Go on Debug -- > Attach process

Now if you scroll down you should see which is the process VS has attached to debug your application (It should appear in a different color -light gray). If the process is not the w3wp.exe it means you are not using IIS for hosting your application and you are probably debugging the wrong process when you make a request from another machine

Upvotes: 2

BenjaminPaul
BenjaminPaul

Reputation: 2941

When you start Visual Studio, start it as Administrator (right click and 'Run as administrator'), then load your project's solution.

Then from the debug menu select "Attach to process..." and ensure that the "Show processes from all users" and "show processes in all sessions" checkboxes are checked, within the Available Processes panel you should be able to scroll through and locate a process that relates to the IIS app pool that you are trying to debug (usually called w3wp.exe).

Attach to this process and refresh the page in your browser, this should allow you to debug.

Many Thanks.

Benjamin

Upvotes: 2

Related Questions