ASP.NET MVC thinks my virtual directory is a controller

…衆ロ難τιáo~ 提交于 2019-11-30 09:22:46

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?

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
            }

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!