views:

74

answers:

5

Hey, I am trying to get a favicon to appear on my webpage. Disclaimer: I have never done this before, but it does seem rather simple.

I have a ico image in a folder called pics that is part of my project. I am trying to do this inside my master page.

 <link rel="Shortcut Icon" href="~/pics/REDIcon.ico"/>

That is correct, right? Is there anything else I should check?

Any help would be appreciated.

EDIT:

my code now looks like:

<link rel="Shortcut Icon" href="pics/REDIcon.ico" type="image/x-icon"/>

This however is still not working properly.

+1  A: 

You have to add type="application/x-icon" in the <link> tag.

EDIT : what's the tilde ? Nothing is necessary to start from current folder

href="pics/REDIcon.ico"
MatTheCat
Hm, something is still not working even after I added that.
PFranchise
not type="image/x-icon" ?
Richard
Edited. No it's application/x-icon
MatTheCat
"image/x-icon" def works, how I've always done it. Google results suggest this is the way to do it.
Richard
Ok so they work both ^^
MatTheCat
Maybe we can all just agree on "image/vnd.microsoft.icon". That's the most official, as far as I can tell: http://en.wikipedia.org/wiki/ICO_(file_format)#MIME_type
mlms13
Is it cross-browser ?
MatTheCat
Ha, figures. Apparently IE6 didn't support "image/vnd.microsoft.icon" (http://stackoverflow.com/questions/1444975/if-i-serve-favicon-ico-as-image-vnd-microsoft-icon-instead-of-image-x-icon-wil). Maybe we can just agree to not use the .ico format? ;)
mlms13
+1  A: 

Is asp.net correctly converting the tilde (~) into something that works with HTML? If this part is going directly into the html, without any pre-processing on the server, I doubt browsers will be able to find the icon because they'll have a hard time interpreting the href. Do you still have this problem if you use an absolute, relative, or root-relative path to the icon?

mlms13
Haha to be honest, I just used the tilde since I used that for the other images on my pages. I am not really sure what it is doing, but I know that it has worked in other instances. I can try other methods and see how that works.
PFranchise
tilde simply causes problems in my experience
m.edmondson
+1  A: 

Add type="image/x-icon" to that link:

<link rel="Shortcut Icon" href="~/pics/REDIcon.ico" type="image/x-icon" / >

You may also need to rewrite that href - not sure how browsers handle tildas (~).

Then restart your browser - they often aggressively cache the presence, or lack of, a favicon.

Edit: I don't know how asp.net frameworks work - but make sure your image has been deployed to the working directory of your app.

Richard
The Browser doesn't handle the tilda, the webserver does when it resolves the request that is coming from the browser, so the behavior of `~` depends on your webserver and how it's configured.
Stephen P
+2  A: 

Just try something like this:

<link rel="shorcut icon" href="imgs/favicon.ico" type="image/x-icon" />
Nervo Verdezoto
+1: .Net will not explode the tilde into the full path. You have to either inject it via the code behind with the path OR just have your markup point to exactly where it's at.
Chris Lively
So, if I have a folder called pics that contains the image and is located where the rest of my code is, my href should look like: href="pics/favicon.ico"
PFranchise
That should be fine. If you don't know where your pics folder is going to be relative to your web page, you can always use a root-relative path. This starts with a forward slash, which represents the top-level directory of your site. If your pics folder is in the root directory, then using "/pics/favicon.ico" should work everywhere, even if your aspx file is in a subdirectory.
mlms13
A: 

1) Add the type="image/x-icon" attribute

2) Remove the ~. The favicon should be in the root of the website(That's where I have always put it and it works). Some browsers may look in predetermined locations for the favicon. Check the returned markup to make sure everything is valid.

3) Clear the browser's cache. I have found that it may take awhile for the icon to start appearing.

Here's an example from one of my pages:

<link rel="shortcut icon" type="image/x-icon" href="http://www.mysite.com/favicon.ico" />
DaveB