开发者

ASP.NET MVC thinks my virtual directory is a controller

开发者 https://www.devze.com 2022-12-28 06:16 出处:网络
I have a virtual directory under my MVC website in IIS called \"Files\". This directory is at the same level as my Views directory. When I link to a file from my MVC app to a file under my Files direc

I have a virtual directory under my MVC website in IIS called "Files". This directory is at the same level as my Views directory. When I link to a file from my MVC app to a file under my Files directory, I get the following erro开发者_Python百科r:

The controller for path '/Files/Images/1c7f7eb8-5d66-4bca-a73a-4ba6340a7805.JPG' was not found or does not implement IController.

It thinks that my Files VD is a controller. How do I access my files like a normal VD without MVC interfering?

Thanks.


When registering routes, try to add the following Ignore rules.

public static void RegisterRoutes(RouteCollection routes)
            {
                /* Ignore static content, see
                 http://weblogs.asp.net/rashid/archive/2009/04/03/asp-net-mvc-best-practices-part-2.aspx 
               */
                routes.RouteExistingFiles = false;
                routes.IgnoreRoute("Content/{*pathInfo}");
                routes.IgnoreRoute("Scripts/{*pathInfo}");
                routes.IgnoreRoute("Styles/{*pathInfo}");
                routes.IgnoreRoute("{*favicon}",
                    new { favicon = @"(.*/)?favicon.([iI][cC][oO]|[gG][iI][fF])(/.*)?" });

                //Ignore handlers and resources
                routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

               // your routes go here
            }


ASP.Net looks for the directory first and then tries to match a controller, so what you are doing should work. Are you sure the file with that name exists and is accessible?


I think you'll have to add a call to routes.Ignore() a static route in your Global.asax file so that .NET MVC knows to ignore the request:

RouteCollection.Ignore(String) - MSDN

0

精彩评论

暂无评论...
验证码 换一张
取 消