Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 994
Kyasa Madhavi Avatar asked Jun 21 '11 10:06

Kyasa Madhavi


People also ask

What is path dot slash?

This is where the dot slash ./ notation comes in. It means “Look in the current directory.” When you use ./, you tell Ubuntu or Fedora or SUSE or whatever Linux distribution you're using to look in the current directory for the command you wish to run, and completely ignore what's on the application PATH.

What is absolute path and relative path in Linux?

An absolute path is defined as specifying the location of a file or directory from the root directory(/). In other words,we can say that an absolute path is a complete path from start of actual file system from / directory. Relative path. Relative path is defined as the path related to the present working directly(pwd) ...

What does dot mean in href?

Yes, ./ means the current working directory. You can just reference the file directly by name, without it.

What is absolute pathname in Linux?

An absolute path is the full path to a file or directory. It is relative to the root directory ( / ). Note that it is a best practice to use absolute paths when you use file paths inside of scripts. For example, the absolute path to the ls command is: /usr/bin/ls . If it's not absolute, then it's a relative path.


2 Answers

  • / - 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/).

like image 76
Oded Avatar answered Sep 23 '22 16:09

Oded


The second won't work because its not a recognised path by anything except asp.net code on the server side. And since your link tag is regular html and not a server control it never gets processed.

like image 40
CRice Avatar answered Sep 25 '22 16:09

CRice