Problem
After making a lot of changes to a web application and thoroughly testing them in our development environment (my local machine), I uploaded the changes to our production server and get the following error message:
Exception Information: The 'href' property had a malformed URL: Cannot use a leading .. to exit above the top directory.. (System.Web.HttpException)
Solution
Apparently, the error message is trying to tell you that a URL you are specifying is trying to access a page that is in a folder somewhere above your website’s root directory (“above the top directory”).
My problem was caused by the following lines of code in my “master” page:
1: HtmlAnchor link = new HtmlAnchor();
2: link.HRef = "../File/FileView.aspx?FileID=" + fileID;
3: link.InnerText = fileFullName + " - " + fileID;
4: phRecentFiles.Controls.Add(link);
Once I changed line 2 from “..” to “~” (root directory), the site worked fine. Here is the final code:
1: HtmlAnchor link = new HtmlAnchor();
2: link.HRef = "~/File/FileView.aspx?FileID=" + fileID;
3: link.InnerText = fileFullName + " - " + fileID;
4: phRecentFiles.Controls.Add(link);