我正在使用IIS 7 Rewrite模块重写传入的URL,如:
至
一切正常,除非在处理重写请求时,我使用MVC的UrlHelper.GenerateUrl()方法:
UrlHelper.GenerateUrl(
"Assets",
"Css",
"Asset",
new RouteValueDictionary(new { site = site.Name, assetPath = assetPath }),
RouteTable.Routes,
controllerContext.RequestContext,
false);
Run Code Online (Sandbox Code Playgroud)
调用此方法会导致HttpException:
System.Web.HttpException: Cannot use a leading .. to exit above the top directory.
at System.Web.Util.UrlPath.ReduceVirtualPath(String path)
at System.Web.Util.UrlPath.Reduce(String path)
at System.Web.VirtualPath.Combine(VirtualPath relativePath)
at System.Web.VirtualPathUtility.Combine(String basePath, String relativePath)
at System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath)
at System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext, String contentPath)
at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues)
Run Code Online (Sandbox Code Playgroud)
查看RequestContext,似乎所有请求路径都是正确的(即,具有重写的值).我似乎无法弄清楚为什么它试图退出顶级目录...我们在路径中没有使用....
我还确保RewriteModule位于IIS中的UrlRouting模块之上.
虽然我可以进入框架方法,但我无法检查任何局部变量(在VS或WinDbg中),因为它已经过编译器优化.
有什么想法吗?