Tigraine
Daniel Hoelbling talks about programming

ASP.NET MVC2 – Make Custom ControllerFactory less painful

June 4th, 2010 . by Daniel Hölbling

When starting a new project on ASP.NET MVC2 I noticed something very annoying. When used with a custom ControllerFactory the framework will throw a HttpException whenever a browser requests a file that is not present on the file system or not mapped by a route.

That means you’ll hit an exception about once per page-load just because Google Chrome is requesting the favicon all the time unless it finds one.

The solution to this is to make the Debugger just step through your CreateController method so no Exceptions will be visible to Visual Studio there:

[System.Diagnostics.DebuggerStepThrough]
public override IController CreateController(System.Web.Routing.RequestContext requestContext,
                                                string controllerName)
{
    return base.CreateController(requestContext, controllerName);
}

This works reasonably well for me right now, at least the pain of hitting F5 every 10 seconds while debugging has gone away. It’s still not perfect since it makes it impossible to actually debug the method if something really goes wrong, but you’ve always got the yellow screen of death to figure out what’s wrong.

Hope this helps!


  • jakescott

    I think you have a problem with your routes… the favicon should be ignored, or else setup IIS to handle it correctly

  • http://www.tigraine.at Daniel Hölbling

    Yes I could have ignored it. But this solution just keeps all HttpExceptions from me that are not originating from actual code, so I'm pretty happy with it.

  • http://www.moncler-down-jackets.com Louis vuitton bags

    The details upstairs are really sensiblelouis vuitton outlet you remind us that anybody who gotta succeeed should make extensive social intercourseLouis vuitton bags,optimistic is a vital personality anybody gonna have!Another,it is important to keep calm when you encounter difficulty,and think out the method to solve problem! air jordan 7 You should try you best to make more friends and good friends are the bridge to help you lead to success!

  • http://www.moncler-down-jackets.com louis vuitton handbags

    Never better evaluation than the upper article says,ugg boots for sale.And I am very pleased I read it by accident.I will go a sightseeing here again ,and of course ,I will tell my friend here I hope more better thing can be whrite in here.I have so many profound or funny thing do benefits to our daily life.By the way, ugg boots salehere are some sites also useful for life,such as shopping online,just have a look. moncler jackets