11
votes

I am trying to use IIS for debugging ASP.NET MVC in Visual Studio. The problem is that if I choose "Use Local IIS Web server" in Visual Studio, I have to choose a virtual directory, something like http://localhost/myapp/

This is a problem because the ASP.NET MVC application is assumed to run from the root directory and the MVC would parse "myapp" as a controller, and when I run the app from Visual Studio/IIS, subsequent requests will be directed to the root anyway.

How to solve this problem? Is there a way to use the IIS website root instead of a virtual directory for Visual Studio debugging?

5

5 Answers

2
votes

Yes you can run an ASP.NET MVC as the root application.

Just use IIS manager to set the home directory for the website to the your application's path.

Then make the appropriate changes in the "Web" tab of your project settings for MVC in Visual Studio.

This is assuming you have windows file permission setup correctly for IIS already.

2
votes

You say that

the ASP.NET MVC application is assumed to run from the root directory and the MVC would parse "myapp" as a controller

However, it is possible to run ASP.NET MVC from a virtual directory by adding wildcard mapping as described in this article:

ASP.NET MVC on IIS 6 Walkthrough

See also this question here on stackoverflow, and the accepted answer which describes the steps followed to solve a similar problem:

ASP.NET MVC How-to use routes when application is published as SubProject of a domain?

1
votes

Go to the properties of your website(under Project Menu). Select the web tab at the bottom and type in the same virtual directory name you use in IIS in the virtual path field. This might solve your problem

1
votes

You can also use Debug->Attach to Process from Visual Studio instead of Start Debugging.

Attach to aspnet_wp.exe, and you'll be able to debug your MVC application regardless of whether or not it's in a virtual directory.

1
votes

Url rewriting can help you to solve the problem. I've implemented solution allowing to deploy MVC application at any IIS version even when virtual hosting is used. http://www.codeproject.com/KB/aspnet/iis-aspnet-url-rewriting.aspx