在使用带有Unity的自定义ControllerFactory时,在asp.net mvc中缺少ContentController注册

时间:2012-02-07 23:13:20

标签: asp.net-mvc asp.net-mvc-3 controller unity-container

我正在使用带有unity的自定义控制器工厂来创建控制器实例。我的工厂看起来像:

public class UnityControllerFactory : DefaultControllerFactory
{

    public override IController CreateController(RequestContext requestContext, string  controllerName)
    {            
        return IoC.Container.Resolve<BaseController>(controllerName + "Controller");
    }

.... 

当我调试此代码时,它正在尝试解析 ContentController (controllerName ==“Content”),当然没有在我的统一配置文件中注册。我试图找出System.Web.MVC中某处是否存在 ContentController ,但我没找到它。

有人可以向我解释,为什么这家工厂正试图解决这个控制器?

感谢

1 个答案:

答案 0 :(得分:1)

这是猜测,但听起来像Content文件夹中的网站静态内容(例如图像,css等)是通过MVC提供的,但不应该。

您使用的服务器是什么?如果您使用IIS 7或IIS Express,它应该使用托管管道,因此这些类型的请求甚至不应该进入MVC运行时。

尝试深入挖掘requestContext实例,以确切了解请求此控制器的内容。