使用Web窗体的URL路由和Favicon的StopRoutingHandler

我有一个网站,我需要添加一个Favicon.ico。 该站点使用带有路由的ASP.NET 3.5 Web窗体编写。 问题是Favicon链接始终返回页面未找到错误。 这是因为路由不知道Favicon.ico的链接应该去哪里,所以它返回Not Found页面。

我试图为favicon添加一个StopRoutingHandler,但它们似乎都不起作用。 以下是我到目前为止尝试过的内容:

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())); 

有谁知道我应该使用什么? 我的favicon.ico链接我试过看起来像这样:

   

它们位于我的标签内。

另外,作为最后一点,我不使用MVC,因为如果我是,我可以使用它:

 routes.IgnoreRoute("{*favicon}", new {favicon=@"(.*/)?favicon.ico(/.*)?"}); 

遗憾的是,IgnoreRoute不适用于Routing Web Forms,因为它不是MVC应用程序。

我用过这个并且它有效:

 routes.Add(new Route("favicon.ico", new StaticFileRouteHandler("~/favicon.ico"))); public class StaticFileRouteHandler : IRouteHandler { public string VirtualPath { get; set; } public StaticFileRouteHandler(string virtualPath) { VirtualPath = virtualPath; } public System.Web.IHttpHandler GetHttpHandler(RequestContext requestContext) { HttpContext.Current.RewritePath(VirtualPath); return new DefaultHttpHandler(); } } 

显然这也有效:

 routes.Add(new Route("favicon.ico", new StopRoutingHandler())); 

我只需要关闭Firefox,清除我的历史并再试一次。