ASP.NET MVC thinks my virtual directory is a controller

前端 未结 3 1169
离开以前
离开以前 2020-12-31 17:04

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

相关标签:
3条回答
  • 2020-12-31 17:40

    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?

    0 讨论(0)
  • 2020-12-31 17:42

    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
                }
    
    0 讨论(0)
  • 2020-12-31 17:42

    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 讨论(0)
提交回复
热议问题