Windsor 正在处理静态文件,如果未找到,则会抛出错误
我刚刚注意到静态文件正在被处理(我猜这是正常的),但问题是如果文件不存在,它似乎会在这里引起异常:
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);
}
}
特别是 GetControllerInstance。
这有道理吗?我应该在那里进行额外的检查以确保它是一个正在处理的类吗?
错误:
The controller for path '/Assets/img/logo.png' could not be found.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(2)
人间☆小暴躁 2024-12-13 02:31:05
如果controllerType为null,则将其传递给基类或返回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示例:"="">https://github.com/ninject/ninject.web.mvc/blob/master/mvc2/src/Ninject.Web.Mvc/NinjectControllerFactory.cs
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您可以尝试 排除静态文件由 ASP.NET MVC 引擎处理以提高性能。
You may try excluding static files from being processed by ASP.NET MVC engine to improve performance.