1

I've come across a background image reference of this form in some HTML code I'm changing.

<a style="background: url('/~/media/Images/Shared/Logos/logo.png')" href="/">Home</a>

I'm not in a position to ask the original author, and I don't understand how the tilde is being evaluated here.

If the url string started "url('~/media/.....'" I understand would be the root of the media user (so you'd better be sure you create that user on all your deployment servers) but the / in front of the tilde has me confused.

All the searches I've done just bring back the home directory explanation, but it doesn't appear to be that.

[edit] This is part of a live site, the logo shows up correctly, I just don't know why.

[edit 2] The site is built using ASP.NET.

[edit 3] The above is a cleaned version of the url from a view/source on the site, not the ASP code.

[edit 4] For those that might be curious, here's the actual working url. I work for the same company, but a different division, and I'm building an internal support tool in Java EE which is borrowing some of the styling. I saw the "/~/...." and couldn't think of a good reason why it would work.

http://business.hibu.co.uk/~/media/Images/Shared/Logos/logo.png
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Steve
  • 154
  • 1
  • 11
  • http://stackoverflow.com/questions/6252471/what-is-the-use-of-tilde-in-url – j08691 Apr 17 '13 at 16:58
  • It's unlikely that it has anything to do with what Unix uses tilde for. It'd take a pretty clueless web admin to set the webroot to the server's root directory. – JJJ Apr 17 '13 at 16:58
  • 1
    What server technology are you using? In ASP.NET, on some controls, you can sometimes use a tilde at the start of a URL to reference the root of the web application. But I don't think ASP.NET would allow it in the middle like this. Also, if it's the server working with this, it would render differently when rendered in the browser. If you view-source on the page, is the tilde still there? – Joe Enos Apr 17 '13 at 16:59
  • Does the image display what it is supposed to? if so check the users home folder – Ibu Apr 17 '13 at 16:59
  • 1
    Well, on Unix systems, `~media` would be the root of the media user. However, I think `/~/` is actually a directory called `~` - whether or not the web server processes that in any special way we cannot tell you. – Mike Christensen Apr 17 '13 at 17:02
  • Image displays as expected, viewing the source is what showed this url. I'm stealing[1] the styles and some of the images for a J2EE based site that requires the same styling. [1] not really stealing, I work for the same company, just a different group. – Steve Apr 17 '13 at 17:03

2 Answers2

3

In ASP.NET, a tilde represents the root of the application (not necessarily the root of the website). But it's only usable in certain circumstances (server controls, controls that are data-bound, or sometimes tags in the head section like script or link).

I wouldn't think an a tag in the regular body would handle it, and I don't think ASP.NET allows the tilde to go anywhere except the beginning of the string anyway.

So I'm guessing you simply actually have a physical directory named ~. In Windows, I don't think the tilde has any special meaning, so it's not the user's home directory or anything like that - just a funky name for a regular directory.

EDIT

After reading your comment that this is the way it's rendered in the browser, and it's working, I'm almost positive that there's a real directory called ~ on your web server. Either that or some kind of URL rewriting going on, which you'd need to see the web.config or IIS settings to see that.

Joe Enos
  • 39,478
  • 11
  • 80
  • 136
  • That's the only answer I can think of that would work, but it does seem a very odd way to to deploy a site. – Steve Apr 17 '13 at 17:14
  • I agree - since the tilde can have a few special meanings, I would never name a real directory that way. – Joe Enos Apr 17 '13 at 17:15
  • I've up-voted your answer, as it's definitely **an** explanation, but I'm going to leave it open for a while in case there's another explanation that neither of us know about. – Steve Apr 17 '13 at 17:23
0

That's likely from their local machine, meaning their home directory. It can never resolve properly from a remote server if the asset path was copied from their development machine.

Otherwise it's a path relative to the home directory on their server.

Alex Mcp
  • 19,037
  • 12
  • 60
  • 93