I have a website where I need to add a Favicon.ico. The site is written using ASP.NET 3.5 Web Forms with Routing. The issue is that the Favicon link always returns a page not found error. This is because the Routing does not know where the link for Favicon.ico should go to so it returns the Not Found page.
I have tried to add a StopRoutingHandler for the the favicon but none of them seem to work. Below are the ones I have tried so far:
routes.Add(new Route("MasterPages/{favicon}.ico", new StopRoutingHandler()));
routes.Add(new Route("{favicon}.ico", new StopRoutingHandler()));
routes.Add(new Route("favicon.ico", new StopRoutingHandler()));
routes.Add(new Route("favicon.ico/{*pathInfo}", new StopRoutingHandler()));
Does anyone know what I should be using? My favicon.ico links I have tried look like this:
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
And they are inside of my <html><head>
tags.
Also, as one final note, I am not using MVC because if I was I could use this:
routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"});
Unfortunately, IgnoreRoute does not work for Routing Web Forms though because it is not an MVC application.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…