Daniel Hoelbling-Inzko talks about programming

ASP.NET MVC2 – Make Custom ControllerFactory less painful

Posted by Daniel Hölbling on June 4, 2010

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:

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!

Filed under net, programmierung
comments powered by Disqus

My Photography business


dynamic css for .NET