locked
How to solve this error in asp.net using c#? RRS feed

  • Question

  • Server Error in '/' Application.

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

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: Cannot use a leading .. to exit above the top directory.

    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:
    [HttpException (0x80004005): Cannot use a leading .. to exit above the top directory.]
       System.Web.Util.UrlPath.ReduceVirtualPath(String path) +9619995
       System.Web.Util.UrlPath.Reduce(String path) +50
       System.Web.Util.UrlPath.Combine(String appPath, String basepath, String relative) +218
       System.Web.UI.Control.ResolveClientUrl(String relativeUrl) +276
       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) +57
       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) +57
       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) +8
       System.Web.UI.Control.Render(HtmlTextWriter writer) +10
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
       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) +8
       System.Web.UI.Page.Render(HtmlTextWriter writer) +29
       System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
       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) +1386
    
    • Moved by Kristin Xie Monday, December 14, 2015 9:48 AM asp.Net related
    Sunday, December 13, 2015 7:42 AM

Answers

  • The asp.net forum is over here:

    https://forums.asp.net/

    Unfortunately, it uses a different tech to this forum so I can't move the thread there.

    Please ask further asp.net questions in those forums, for better support.

    .

    I think as it says a leading .. then Viorel's point is probably correct.

    The double dot notation means parent of whatever the current folder is.

    If you start a url with .. on something is already in the root of your web site then that's going try and go look outside the web site.

    The chances are that security will stop that working.

    If you didn't intend using a url pointing somewhere outside your web site then you can find that .. and fix it up.

    If you did intend it then you need to consider what to change and whether to maybe use an absolute address.

    Even if you could get it to work it's a bad idea to use relative url from one web site to somewhere else.

    It would be very easy to change the location of that resource and not realise your web site is relying on it being there.

    Time for a Plan B.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    • Proposed as answer by Just Karl Tuesday, December 15, 2015 8:13 PM
    • Marked as answer by Dave PatrickMVP Saturday, December 19, 2015 4:17 AM
    Sunday, December 13, 2015 3:01 PM

All replies

  • Probably your code is trying to access a parent folder that is not a part of your Web site. For example, you have a relative address such as “~/../Images/MyImage.gif”.

    Sunday, December 13, 2015 9:06 AM
  • The error has noting to do with C#, and you should post to the ASP.NET forum that you can find by using Bing or Google.
    Sunday, December 13, 2015 10:54 AM
  • The asp.net forum is over here:

    https://forums.asp.net/

    Unfortunately, it uses a different tech to this forum so I can't move the thread there.

    Please ask further asp.net questions in those forums, for better support.

    .

    I think as it says a leading .. then Viorel's point is probably correct.

    The double dot notation means parent of whatever the current folder is.

    If you start a url with .. on something is already in the root of your web site then that's going try and go look outside the web site.

    The chances are that security will stop that working.

    If you didn't intend using a url pointing somewhere outside your web site then you can find that .. and fix it up.

    If you did intend it then you need to consider what to change and whether to maybe use an absolute address.

    Even if you could get it to work it's a bad idea to use relative url from one web site to somewhere else.

    It would be very easy to change the location of that resource and not realise your web site is relying on it being there.

    Time for a Plan B.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    • Proposed as answer by Just Karl Tuesday, December 15, 2015 8:13 PM
    • Marked as answer by Dave PatrickMVP Saturday, December 19, 2015 4:17 AM
    Sunday, December 13, 2015 3:01 PM