ASP.. NET MVC: RouteLink从区域到根抛出异常

本文关键字:区域 抛出异常 RouteLink NET MVC ASP | 更新日期: 2023-09-27 18:17:02

我们有一个ASP。. NET MVC 3 WebApp,带有一个管理区域(areaname = 'admin')。

在管理区的页面(Razor => Index.cshtml)上,我调用:

@Html.RouteLink("Preview", Resources_Blog.Route_Name_StaticPages, new { pagename = page.Slug, area = "" }, new {target = "_blank", Request.Url.Scheme})

Route在全局中声明。像这样:

routes.MapRoute(
            Resources_Blog.Route_Name_StaticPages, // Routename
            Resources_Blog.Route_Url_StaticPages + "/{pagename}", // URL with parameters
            new { controller = "Home", action = "Page", page = UrlParameter.Optional, area = "" }, // Defaults
            new[] { "My.Namespace.Controllers" }
        );

资源:

Route_Name_StaticPages = "StaticPages" 
Route_Url_StaticPages  = "static"

当页面被渲染或应该被渲染时,我得到这个异常:

System.Web.HttpException (0x80004005): 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.HttpResponse.ApplyAppPathModifier(String virtualPath)
at System.Web.Routing.RouteCollection.NormalizeVirtualPath(RequestContext requestContext, String virtualPath)
at System.Web.Routing.RouteCollection.GetVirtualPath(RequestContext requestContext, String name, RouteValueDictionary values)
at System.Web.Mvc.RouteCollectionExtensions.GetVirtualPathForArea(RouteCollection routes, RequestContext requestContext, String name, RouteValueDictionary values, Boolean& usingAreas)
at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues)
at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, String protocol, String hostName, String fragment, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues)
at System.Web.Mvc.HtmlHelper.GenerateLinkInternal(RequestContext requestContext, RouteCollection routeCollection, String linkText, String routeName, String actionName, String controllerName, String protocol, String hostName, String fragment, RouteValueDictionary routeValues, IDictionary`2 htmlAttributes, Boolean includeImplicitMvcValues)
at System.Web.Mvc.Html.LinkExtensions.RouteLink(HtmlHelper htmlHelper, String linkText, String routeName, RouteValueDictionary routeValues, IDictionary`2 htmlAttributes)

不幸的是,异常只在生活系统上抛出,而不是在开发系统上抛出,所以我不能真正调试它。这是IIS 7。

我还尝试调用routelink方法,但没有area参数,也会抛出异常:

Html.RouteLink("Preview", Resources_Blog.Route_Name_StaticPages, new { pagename = page.Slug, area = "" }, new {target = "_blank", Request.Url.Scheme})

另一个尝试调用RouteUrl,但也失败了:

<a target="_blank" href="@Url.RouteUrl(Resources_Blog.Route_Name_StaticPages, new { pagename = page.Slug })">@Resources_Administration.Pages_StaticPage_Show</a>

有人能帮帮我们吗?

是iis配置问题还是区域配置错误?

ASP.. NET MVC: RouteLink从区域到根抛出异常

"Solved" the problem

VA-Test成功地注入一个包含的鼻涕虫 "'..'..'..'..'..'..".