Using Cassini with a virtual path that contains do

2019-07-30 03:14发布

问题:

I am working on an existing project in ASP.NET witch is based in a folder that contains dots

http://localhost/My.Awesome.WebClient/

This setup works fine using the integrated Visual Studio Develompent Server, but fails when I add MVC content and try to access it (Error 404 Resource not found).

http://msdn.microsoft.com/en-us/library/ee941656.aspx seems to explain the issue:

If you create a file system Web site in Visual Studio 2010 and the Web site is in a folder that contains a dot (.) in the folder name, URL routing will not work reliably. An HTTP 404 error is returned from some virtual paths. This occurs because Visual Studio 2010 launches the Visual Studio Development Server (Cassini) using an incorrect path for the root virtual directory.

However, the project is a Web Project, not a Web Site, and it only failed when I started using MVC.

The problem can be easily reproduced:

  1. File - New - Project - ASP.NET MVC 3 Web Application
  2. Edit project settings, Web: Use Visual Studio Development Server
  3. Set the virtual path to something that contains a dot
  4. Try to run the site

Is there a way to get this to work, besides using IIS instead of Cassini?

Edit:

I did find a workaround just now. It does not really work in a deployment scenario, but it may help in finding a solution:

in my Global.asax.cs file:

        routes.MapRoute(
            "Default", // Route name
            // Notice that I added the virtual path here
            "My.Awesome.WebClient/{controller}/{action}/{id}", // URL with parameters
            new { action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

        // This is also new
        routes.MapRoute(
            "Root", // Route name
            "", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

Using this workaround, my MVC-Sites work, but only with the following url:

http://localhost/My.Awesome.WebClient/My.Awesome.WebClient/

回答1:

If you don't get an answer to this question (personally, I'm not aware of any way around this), I would recommend using "IIS Express", which is available as a free download. It can be installed on development machines and you can control a lot of server settings with your web.config file, which is fairly unobtrusive.

You can download it here:

http://www.microsoft.com/download/en/details.aspx?id=1038

I use IIS Express exclusively now; Cassini has always lacked features and IIS Express avoids me having to configure IIS for each web application.