4

I have the following link inside my asp.net mvc razor view:-

<a class="brand" href="~/Home/Index/"> <img alt="test" src="~/Content/logo.png" /> </a>

But i am not sure what does the symbol ~ inside the src & href do ? as removing this symbol will still reference to the correct imag and the correct url ? can anyone advice please ?

Thanks

John John
  • 1
  • 72
  • 238
  • 501

4 Answers4

4

http://msdn.microsoft.com/en-us/library/ms178116(v=vs.100).aspx

~ means root directory of your application.

Following SO post may help to know more.

slash(/) vs tilde slash (~/) in style sheet path in asp.net

In your case removing the ~ from path will make your path absolute. Then the url will become http://example.com/absoulte/path. If your project root directory and web root is same, it will make no difference. You may also want to visit these links.

http://www.boogiejack.com/server_paths.html

Absolute path & Relative Path

Community
  • 1
  • 1
chanchal118
  • 3,551
  • 2
  • 26
  • 52
  • Removing '~' will make your path absolute path after site host. – chanchal118 Dec 31 '13 at 11:13
  • i think the difference is as follow, if i deploy my web application on IIS under let say www.example.com/myApp , then / will return www.example.com , while ~/ will return www.example.com/myApp. so i should use ~ since on production server i might deploy my application under www.ourcompany.com/CustomApp/myApp, so i need the link to refernece www.ourcompnay.com/CustomApp/myApp nad not just www.ourcompnay.com. what do u think is my point right ? – John John Dec 31 '13 at 11:33
  • Your msdn link was very usefull, but currently i am assuming that any code inside asp.net mvc Razor view will be processed as a server side control, without explicitly writing this? that why ~ was recognized well ,, what do u think? – John John Dec 31 '13 at 12:24
  • @johnG Yes it was processed as server side control. – chanchal118 Dec 31 '13 at 12:27
1

The ~ symbol represents the currently logged in users home directory on a linux/unix system.

mathematician1975
  • 21,161
  • 6
  • 59
  • 101
  • but i am working on a windows server & IIS and not on a unix server, so does this have any meaning on windows server ? – John John Dec 31 '13 at 11:11
  • @johnG I am not certain - it doesnt work as intended on my windows machine but this answer may be of use to you http://stackoverflow.com/questions/3077558/use-of-tilde-in-asp-net-path – mathematician1975 Dec 31 '13 at 11:23
1

"~" is notation for webroot.. if you have IIS C:/inetpub/wwwroot/ is your webroot..

it has its existence (origin) from UNIX ~ which denotes home directory

Ashish
  • 1,856
  • 18
  • 30
0

~ is your 'home' folder, on Unix it is eg. /home/andy (it is taken from $HOME variable - and it can be set by you to any other folder)

Andy
  • 1,035
  • 1
  • 12
  • 28