Using URL Routing for Web Forms and StopRoutingHandler for Favicon

后端 未结 1 978
旧巷少年郎
旧巷少年郎 2020-12-16 21:02

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

相关标签:
1条回答
  • 2020-12-16 21:39

    I used this and it worked:

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

    Apparently this works too:

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

    I just needed to close Firefox, clear my history and try again.

    0 讨论(0)
提交回复
热议问题