ASP.Net MVC - Why is a controller being created for favicon.ico?
Asked Answered
P

1

14

I am using a custom ControllerFactory (to use Castle Windsor's IOC to create controllers), and I notice it's getting requests to create a controller for "favicon.ico". I have put a favicon.ico file in my Content folder, but I'm still getting these requests.

How do I resolve this and serve static content without trying to create controllers?

Psychological answered 30/12, 2009 at 7:34 Comment(1)
This was happening to me because browsers try to look for the favicon.ico in your root and for some reason asp.net thinks it's a controller, and it filled my logs with the error "favicon.ico controller not found", I don't know if this is what you are talking about.Beamer
R
28

Add the following route:

routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
Reminiscence answered 30/12, 2009 at 7:37 Comment(3)
Why not just routes.IgnoreRoute("favicon.ico")?Wench
The suggested IgnoreRoute ignores favicon.ico in any folder, not just the root. I think it comes from Phil Haack's blog (haacked.com/archive/2008/07/14/…)Biffin
Oh, and it should be \. for the . in the regular expression i.e. favicon\.icoBiffin

© 2022 - 2024 — McMap. All rights reserved.