开发者

Static files are being processed by Windsor and throwing errors if not found

I just noticed that static files are being processed (I guess that is normal) but the problem is if a file doesn't exist it seems to be causing an exception here:

public class WindsorControllerFactory : DefaultControllerFactory
    {
        private readonly IKernel _kernel;

        public WindsorControllerFactory(IKernel kernel)
        {
            this._kernel = kernel;
        }

        public override void ReleaseController(IController controller)
        {
            _kernel.ReleaseComponent(controller);
        }

        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            if 开发者_高级运维(controllerType == null)
            {
                throw new HttpException(404, string.Format("The controller for path '{0}' could not be found.", requestContext.HttpContext.Request.Path));
            }
            return (IController)_kernel.Resolve(controllerType);
        }
    }

Specifically the GetControllerInstance.

Does this make sense? Should I put extra checks in there to make sure it is a class being processed?

The error:

The controller for path '/Assets/img/logo.png' could not be found.


You may try excluding static files from being processed by ASP.NET MVC engine to improve performance.


If controllerType is null, pass it to the base class or return null

public class WindsorControllerFactory : DefaultControllerFactory
{
    private readonly IKernel _kernel;

    public WindsorControllerFactory(IKernel kernel)
    {
        this._kernel = kernel;
    }

    public override void ReleaseController(IController controller)
    {
        _kernel.ReleaseComponent(controller);
    }

    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
    {
        if (controllerType == null)
            return base.GetControllerInstance(requestContext, controllerType);

        return (IController)_kernel.Resolve(controllerType);
    }
}

Ninjet sample: https://github.com/ninject/ninject.web.mvc/blob/master/mvc2/src/Ninject.Web.Mvc/NinjectControllerFactory.cs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜