I have been using custom 404 error pages for a long time -- I wrote an
article on the technique for MSDN in October of 1999, and have a straightforward example in
Article #2162. I have tried several experiments using this feature, and have learned some interesting things from my research.
One of these is that when you add a favorite in Internet Explorer, the browser searches for the web site's "favorites icon" - or favicon.ico. (For more info, see
www.favicon.com.) This is how your favorites end up with branded icons for some of the web sites you go to, and how http://www.msn.com/ and other web sites have their icon in IE's address bar.
Note that you can use a different ICO file if you prefer... favicon.ico is only the default. You can override it with the following tag:
| <LINK REL="SHORTCUT ICON" HREF="http://www.wherever.com/iconName.ico"> |
Well, if the browser searches for this file and can't find it, you can capture the event with a custom 404 page. I simply created a table to increment a counter:
CREATE TABLE FavIcon ( cnt INT ) |
Then a stored procedure to handle the updates:
CREATE PROCEDURE FAQ_bumpFavIcon AS BEGIN UPDATE FavIcon SET cnt = cnt + 1 END |
And in my custom error page for 404 errors, I have the following code:
<% ' ... valid connection "conn" established qs = lcase(Request.ServerVariables("QUERY_STRING")) if right(qs,12)="/favicon.ico" then conn.execute("EXEC FAQ_bumpFavIcon") end if %> |
Now, as Eoin has pointed out, this doesn't necessarily work in all browsers. For example, FireFox always requests the favicon.ico, so if you have a high volume of FireFox users, you may be padding your numbers quite a bit. So you will need to isolate the code to only run in Internet Explorer. You can parse the User Agent string:
<% ua = lcase(Request.ServerVariables("HTTP_USER_AGENT")) if instr(ua, "(compatible; msie ")>0 then ' we can assume this is IE, though it is not conclusive ' due to user agent cloaking features available... ' ... valid connection "conn" established qs = lcase(Request.ServerVariables("QUERY_STRING")) if right(qs,12)="/favicon.ico" then conn.execute("EXEC FAQ_bumpFavIcon") end if end if %> |