Hint: The Mysterious Tilde

by: Allan Thræn

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.

06 March 2008


Comments

  1. Even the sun has its spots, Allan... ;)
  2. i actually am stuckk on a quiz question in my univ. a pic of roxio toast 9 titanium is given and the possible hints were "do not keep tilde pages" and "gedit".. i ve googled but din get a specific answer . i fouund that roxio toast 9 is default for mac os x but got abstract articles regarding tilde..can u help me out? thank you (in advance )
Post a comment    
User verification Image for user verification  
Allan Thræn

About me

I'm  a  developer on the Research team, currently stationed in our US office. My technical interests are typically focused around search, information management, artificial intelligence, personalization, tracking user behavior, usability in content management and most of all making cool plugins and code samples for EPiServer.

On top of this blog I have the blog Allan On Technology and I often crosspost.

 

 

 


Syndications


Archive


Tag cloud

EPiTrace logger