Asp.net mvc 2 为什么此IgnoreRoute呼叫与这些请求匹配?

Asp.net mvc 2 为什么此IgnoreRoute呼叫与这些请求匹配?,asp.net-mvc-2,asp.net-mvc-routing,ignoreroute,Asp.net Mvc 2,Asp.net Mvc Routing,Ignoreroute,我有一个本地化httphandler,它运行在我的ASP.NETMVC2内容文件夹的上下文中(它所做的部分工作是编译/Content/css中的.less文件)。此特定请求集的默认路由如下所示: context.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); context.MapRoute( "Area_default", "{controller}/{action}/{id}", new { controller

我有一个本地化httphandler,它运行在我的ASP.NETMVC2内容文件夹的上下文中(它所做的部分工作是编译/Content/css中的.less文件)。此特定请求集的默认路由如下所示:

context.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

context.MapRoute(
    "Area_default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new { controller = new VirtualDirectoryConstraint("VDirectory1") },
    new string[] { "Namespace.One.MVC" }
);
(顺便说一句——我认为这与此无关,但只是以防万一——如果请求不是来自传入的应用程序路径/虚拟目录,VirtualDirectory Constraint会拒绝此路由上的匹配)

使用此配置可以调用
http://server.net/VDirectory1/Content/css/LessCompiler.axd
失败,因为没有ContentController类。一切都很好

当我加上

context.Routes.IgnoreRoute("{Content}/{*pathInfo}");
该调用成功,但后续调用

http://server.net/VDirectory1/Localization/ClientScript/en-US.js

失败。查看Phil Haack的RoutedBugger工具,这些调用与内容IgnoreRoute匹配:

True    {Content}/{*pathInfo}   (null)  (null)  (null)
因此,不会分别路由到LocalizationController和AuthorizationController


显然,我对IgnoreRoute应该如何使用以及为什么特定的IgnoreRoute与这些请求相匹配有些误解。我遗漏了什么?

您的IgnoreRoute不应该使用
内容而不是
{Content}

context.Routes.IgnoreRoute("Content/{*pathInfo}");
目前,
{Content}
可能作为一个变量扩展为nothing,这使得pathinfo匹配所有内容

context.Routes.IgnoreRoute("Content/{*pathInfo}");