Search code examples
asp.netiis-6directorywindows-server-2003

ASP.Net error: "Cannot use a leading .. to exit above the top directory"


I'm seeing this error several times an hour on my production site and am not quite sure how to fix it. I've grepped the source code and I am not using "../" anywhere in my code to generate a path.

My application is running on IIS6 on Win2003 Server. It's using URLRewriter.Net to allow the site to have friendly URLs, and I'm wondering if this could be contributing to the problem.

I've already Googled for a solution and have found several possibilities but none have worked for me.

I've tried creating a new App_Browser file to force the tagwriter settings to use a specific HtmlTextWriter, as suggested in one of the most popular solutions, but that hasn't worked for me. I haven't seen any other likely solutions.


Solution

  • It's probably due to using "~/something", probably on a Hyperlink control. When the physical file is at a different directory level from the friendly URL, ASP.NET uses too many ../'s in the relative URL that it generates, giving this error. If you can't just use an absolute URL instead, I believe that you can use Page.ResolveUrl("~/foo/bar") to get the proper relative URL.