This is a really quick post, mostly for myself so the next time I have this issue I can find the answer (yes, I often search my blog before google).
The error “Cannot use a leading .. to exit above the top directory” can be thrown by ASP.NET when you use relative paths incorrectly. If you generate a url with too many “../../../” levels in it that would take the user above the root directory, you can generate the exception.
Why the exception? Security I guess, but it’s a client URL and the server should know better than let the internet walk the C drive, but at one time a company in Redmond had servers with just such issues. My problem isn’t with the unneeded exception (after all, it would just be a 404 link worst case), but with the bug in ASP.NET that causes it.
If you are using Server.Transfer or HttpContext.RewritePath to redirect a request (say map it to a template page) and have a HyperLink control with the ImageUrl property set, you win an extra “../” by the framework. The fix is to wrap the HyperLink control around an Image control.
In code, if you have:
<asp:HyperLink runat="server" NavigateUrl="~/FlyPage.aspx"
ImageUrl="~/Images/DeadFly.png" Width="200" Height="200"/>
Change it to:
<asp:HyperLink runat="server" NavigateUrl="~/FlyPage.aspx">
<asp:Image runat="server" ImageUrl="~/Images/DeadFly.png"
Width="200" Height="200" />
</asp:HyperLink>
(I said it was a quick post… now go register for CodeStock!)
Posted
03-12-2010 3:09 PM
by
Michael C. Neel