StructureMap controller factory and null controller instance in MVC

前端 未结 4 1034
不知归路
不知归路 2021-02-08 10:38

I\'m still trying to figure things out with StructureMap and one of the issues i\'m running into is my Controller Factory class blowing up when a null controller type is passed

4条回答
  •  醉梦人生
    2021-02-08 10:51

    Most browser are looking for a favicon.ico when you load a site, and there is probably some caching involved with this behavior, this might explain the odd "Only fail on the first build" thing you mentionned.

    In my case this was causing the problem of the null controller type in the controller factory.

    Adding a routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); in global.asax makes the error go away, the request should fall through to the filesystem without MVC looking for a favico.ico controller in your code.

    Here is a link to Gunnar Peipman post about this

    I found out by overriding GetControllerType(string controllerName) in my custom controller factory class and checking what the controllerName value was for each request.

提交回复
热议问题