Archive for April 21st, 2009

UrlRewrite – Virtual Directories and the Tilde

Last week I was making some SEO changes to one of the projects I’m working on when I ran into a problem using the tilde specifier in my runat=”server” URLs. For example,

<asp:HyperLink
     ID="m_hlContedit"
     runat="server"
     NavigateUrl="~/tools/ContentEdit/Menu.aspx"
     >Site Admin Home</asp:HyperLink>

Instead of the ~ resolving to the application directory, it was resolving to the directory the browser thought I was in. This was cause by the fact that I was doing a UrlRedirect from a subdirectory to an ASPX file in the root of my application while handling a 404 error. But the ASPX file was in the root directory. So .NET thought I was in the root directory of my application while the browser thought I was in some sub directory.

Read the rest of this entry »

Bear