Hint: The Mysterious Tilde

blog header image

Here's a typical rookie mistake that can even puzzle experienced developers from time to time.

When working with EPiServer CMS 5 you can get quite used to using the tilde character ("~") in various URL's. When you are coding against a web application in it's own folder it's an easy way to make relative links - and also used several places in the UI.

However, a classic mistake is to keep using the tilde when coding regular HTML on your pages like this:

<link rel="stylesheet" href="~/styles/style.css"/>

However, that won't work - and soon a rookie (read: me) will be freaking out, considering access rights, VPP's, etc before realizing the basic nature of his mistake: tilde is interpreted by ASP.NET as a shortcut to HttpRuntime.AppDomain AppVirtualPath property. The above tag isn't handled by ASP.NET but rather passed directly out. This leaves you with 2 options:

  1. Don't use tildes in tags like the one above - instead use normal relative URL's.
  2. Add "runat=server" to the tag to make ASP.NET handle it.
Recent posts