Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up virtual directory when using IIS for ASP.NET MVC debugging

Tags:

asp.net-mvc

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?

like image 683
ycseattle Avatar asked May 04 '09 17:05

ycseattle


People also ask

How do I create a virtual directory for ASP NET application in IIS?

To create a virtual directory with IIS Manager for an ASP.NET application. In IIS Manager, expand the local computer and the Sites folder. Right-click the site or folder where you want to create the virtual directory and then click Add Virtual Directory.

How do I debug MVC in IIS?

To start debugging, select IIS Express (<Browser name>) or Local IIS (<Browser name>) in the toolbar, select Start Debugging from the Debug menu, or press F5. The debugger pauses at the breakpoints. If the debugger can't hit the breakpoints, see Troubleshoot debugging.

How do I change the virtual directory path in IIS?

Open IIS Manager by Typing inetmgr on Start Menu or Run. Click On Sites on the Left navigation of IIS Manager. Right Click on Site where you want to Add Virtual Path and Choose Add Virtual Directory. Put the Short Name of Application/Website in Alias Field.


2 Answers

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.

like image 71
Joseph Kingry Avatar answered Sep 28 '22 08:09

Joseph Kingry


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?

like image 38
Ole Lynge Avatar answered Sep 28 '22 09:09

Ole Lynge