小编Pau*_* pk的帖子

ASP.NET MVC UrlHelper.GenerateUrl异常:"无法使用前导..退出顶级目录"

我正在使用IIS 7 Rewrite模块重写传入的URL,如:

HTTP://服务器/年/所有

至

HTTP://服务器/应用/控制器/年/所有

一切正常,除非在处理重写请求时,我使用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中),因为它已经过编译器优化.

有什么想法吗?

asp.net url-rewriting asp.net-mvc-2

17
推荐指数
2
解决办法
3920
查看次数

标签 统计

asp.net ×1

asp.net-mvc-2 ×1

url-rewriting ×1