scaryman
scaryman

Reputation: 1900

Debugging ASP.NET Cannot use a leading .. to exit above the top directory

I'm getting the dreaded Cannot use a leading .. to exit above the top directory.

Unfortunately for me it's being generated...somewhere?....out of my control. Are there tools that will help me find out where it's being generated? Or even the actual text of the hyperlink? Maybe intellitrace somehow?

Yes, there's a million google results for it. I know what I need to fix, I just have no idea where the problem is actually occurring.

I tried overriding the render event, and then calling ResolveClientURL on every single HtmlLink object I could find by walking the control tree from the base, but that never throws an exception or does anything wrong. Could it be dying only during base.render because I'm calling ResolveClientURL from a page in /v5/plugins/dashboard and the base page is in /v5/?

Here's the bit I wrote to debug manually. I would expect this code to throw an exception.

  protected override void Render(HtmlTextWriter writer)
  {
    foreach (Control c in base.Controls)
    {
      Trace.Write("New base control");
      var baseParent = c;// findBaseParent(c);
      Trace.Write(baseParent.GetType().ToString());
      renderChillunsRecursive(baseParent, 0);
    }
    base.Render(writer);
  }
  private int total;
  private void renderChillunsRecursive(Control c,int depth)
  {
    var chilluns = c.Controls;
    foreach (Control a in chilluns)
    {
      renderChillunsRecursive(a,depth +1);
      total++;
    }
    string otherString = String.Empty;
    if(c.GetType() == typeof(HtmlLink))
    {
      HtmlLink theLInk = ((HtmlLink) c);
          otherString = theLInk.Href;
      otherString += " - " + theLInk.ResolveClientUrl(theLInk.Href);
    }
    Trace.Write(String.Format("{0} - {1} - {2} - {3} - {4}",depth,total,c.GetType(),c.ToString(),otherString));
  }

Stack Trace

[HttpException (0x80004005): Cannot use a leading .. to exit above the top directory.]
   System.Web.Util.UrlPath.ReduceVirtualPath(String path) +8886247
   System.Web.Util.UrlPath.Reduce(String path) +52
   System.Web.Util.UrlPath.Combine(String appPath, String basepath, String relative) +214
   System.Web.UI.Control.ResolveClientUrl(String relativeUrl) +180
   System.Web.UI.HtmlControls.HtmlLink.RenderAttributes(HtmlTextWriter writer) +74
   System.Web.UI.HtmlControls.HtmlLink.Render(HtmlTextWriter writer) +42
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +8703574
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.HtmlControls.HtmlHead.RenderChildren(HtmlTextWriter writer) +17
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +8703574
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +8703574
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   FileBasePage.Render(HtmlTextWriter writer) +2331
   FileDetails.Render(HtmlTextWriter writer) in c:\inetpub\V5 - Development\Plugins\Dashboard\FileDetails.aspx.cs:690
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +8703574
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

Upvotes: 3

Views: 7106

Answers (2)

rakshpal
rakshpal

Reputation: 11

remove ../ and place ~/ from master page and error page rectify error-Cannot use a leading .. to exit above the top directory.

Upvotes: 1

scaryman
scaryman

Reputation: 1900

Nobody has answered my actual question -

Are there tools that will help me find out where it's being generated? Or even the actual text of the hyperlink? Maybe intellitrace somehow?

But we found that somehow IIS dll security was getting in the way. The command c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\caspol.exe -m -ag 1 -url "file:////C:\inetpub\V5 - Development\*" FullTrust -exclusive on fixed our issue - it's similar to right clicking a dll and selecting unblock. (our remote deploy for this test server consisted of zipping up the site and dropboxing it to the server, so windows applied some extra security stuff to it). See http://blogs.msdn.com/b/narahari/archive/2010/06/03/system-security-securityexception-request-for-the-permission-of-type-system-web-aspnethostingpermission-system-version-2-0-0-0-culture-neutral-publickeytoken-b77a5c561934e089-failed.aspx for more info.

We think because IIS didn't like the DLLs in the sites bin folder it went and found a useful one from the gac, at which point the ReduceVirtualPath failed because it was not, in fact, anywhere near the website directory.

Upvotes: 0

Related Questions