Why should I use @Url.Content("~/blah-blah-blah")?

Usually, your web application is published as: www.yoursite.com/. The ~ character matches the root of the site /.

However, if you publish your site withing a virtual directory www.yoursite.com/mywebapp/, the the ~ character would match "/mywebapp/". Hard-coding Urls with "/" character would cause wrong page references.


Mapping virtual paths is it's only purpose. If you do not ever need to map them and are sure your app or it folders will not sit under other apps then it won't serve you any purpose.

From the docs note if you don't use ~ you get no change in the result anyways: "Remarks If the specified content path does not start with the tilde (~) character, this method returns contentPath unchanged. "


It is usefull if your applications root path is not the root path of your server. Url.Content("~/") returns the root folder of your application.