无法使用前导..退出顶层目录。错误

时间:2019-04-29 08:15:28

标签: c#

`Cannot use a leading .. to exit above the top directory.`

`[HttpException (0x80004005): Cannot use a leading .. to exit above the top directory.]
   System.Web.Util.UrlPath.ReduceVirtualPath(String path) +9985452
   System.Web.Util.UrlPath.Reduce(String path) +50
   System.Web.Util.UrlPath.Combine(String appPath, String basepath, String relative) +217
   System.Web.UI.Control.ResolveClientUrl(String relativeUrl) +266
   System.Web.UI.HtmlControls.HtmlLink.RenderAttributes(HtmlTextWriter writer) +74
   System.Web.UI.HtmlControls.HtmlLink.Render(HtmlTextWriter writer) +41
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +66
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
   System.Web.UI.HtmlControls.HtmlHead.RenderChildren(HtmlTextWriter writer) +21
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +66
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +13
   System.Web.UI.Control.Render(HtmlTextWriter writer) +12
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +66
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +13
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +66
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1303
`

我的项目运行正常,现在我不知道会发生什么,每次导航时都会出现错误。

我尝试使用完整链接 1. <a class="nav-link" href=" http://localhost:64406/Test/Product.aspx">Add Products</a>

  1. <a class="nav-link" href="../../Test/Product.aspx">Add Products</a>

  2. <a class="nav-link" href="../Test/Product.aspx">Add Products</a>

  3. <a class="nav-link" href="~/Test/Product.aspx">Add Products</a>
  4. <a class="nav-link" href="Test/Product.aspx">Add Products</a>

什么都没有。

我到处搜索以尝试找到解决方案,但没有任何解决方案能够解决我的问题。也访问了此链接Cannot use a leading ../ to exit above the top directory,但无法解决我的问题。

1 个答案:

答案 0 :(得分:0)

这将帮助所有努力解决此问题的人,我通过将所有链接<a class="nav-link" href="../Test/Product.aspx">Add Products</a>替换为<a class="nav-link" href="/Test/Product.aspx">Add Products</a>来解决了这个问题

这包括所有CSS和Js链接<link rel="stylesheet" href="/css/style.css"/>

不仅仅是替换1个链接,而是替换您的MasterPage中的所有链接。