Slash (/) vs tilde slash (~/) in style sheet path

Kyasa Madhavi picture Kyasa Madhavi · Jun 21, 2011 · Viewed 43.8k times · Source

ASP.NET offers two ways to specify paths for style sheets:

<link href="/common/black_theme/css/style.css" rel="stylesheet">   (this is working)
<link href="~/common/black_theme/css/style.css" rel="stylesheet">  (this is not working)
  • How are these paths resolved?
  • Why are the generated paths different?
  • Which one should I pick in which case?

As per my knowledge, ~ represents the root directory of the application. "common" is the folder below the website root (named testsite.demo) in IIS.

Physical path: D:\Physicalpath\WarpFirstSite\testsite.demo
"common" folder: D:\Physicalpath\WarpFirstSite\testsite.demo\common

Answer

Oded picture Oded · Jun 21, 2011
  • / - Site root
  • ~/ - Root directory of the application

The difference is that if you site is:

http://example.com

And you have an application myapp on:

http://example.com/mydir/myapp

/ will return the root of the site (http://example.com),

~/ will return the root of the application (http://example.com/mydir/).