我有一个本地化的httphandler,它在我的ASP.Net MVC2 Content文件夹的上下文中运行(它正在做的一部分是编译/ 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" }
);
(顺便说一句 - 我认为它不相关,但以防万一 - 如果请求不是来自传入的应用程序路径/虚拟目录,VirtualDirectoryConstraint会拒绝此路由上的匹配)
使用此配置,对http://server.net/VDirectory1/Content/css/LessCompiler.axd
的调用失败,因为没有ContentController类。一切都很好。
当我添加
context.Routes.IgnoreRoute("{Content}/{*pathInfo}");
该呼叫成功,但随后调用
http://server.net/VDirectory1/Localization/ClientScript/en-US.js
和
http://server.net/VDirectory1/Authorization/ClientScript
失败。看看Phil Haack的RouteDebugger工具,这些调用与Content IgnoreRoute路由匹配:
True {Content}/{*pathInfo} (null) (null) (null)
因此不会分别路由到LocalizationController和AuthorizationController。
显然,我误解了IgnoreRoute应该如何使用以及为什么特定的IgnoreRoute匹配这些请求。我错过了什么?
答案 0 :(得分:2)
你的IgnoreRoute不应该使用Content
代替{Content}
吗?
context.Routes.IgnoreRoute("Content/{*pathInfo}");
目前,{Content}
可能正在作为变量扩展为空,这使得pathinfo匹配所有内容。