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 am a product manager @ EPiServer, with a passion for the more geeky side of things. My technical interests are typically focused around user problems, user experience,  search, information management, artificial intelligence and  personalization

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

DISCLAIMER: Unless otherwise stated in the posts, this blog expresses my personal opinions, experiments and views, not necessarilly the views of EPiServer AB.

 180 page views this week.

 

 

Syndications


Archive


Tag cloud

EPiTrace logger