我一直在研究我的第一个MVC网络应用程序,自启动它以来,我一直在收到这封电子邮件,这封邮件是从我在Global.asax中的Application_errror方法自动发送的
这只是一条404消息吗?它会如何生成?我没有任何名为Text的控制器,我有HomeController和AssistanceController ......
System.InvalidOperationException: The IControllerFactory 'FightTheFloods.Infrastructure.NinjectControllerFactory' did not return a controller for the name 'text'.
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
The IControllerFactory 'FightTheFloods.Infrastructure.NinjectControllerFactory' did not return a controller for the name 'text'.
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
这是我的控制器工厂代码
public class NinjectControllerFactory : DefaultControllerFactory
{
private IKernel kernel = new StandardKernel(new FightTheFloodsServices());
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
return null;
return (IController)kernel.Get(controllerType);
}
/// <summary>
/// Configuration for Ninject
/// </summary>
private class FightTheFloodsServices : NinjectModule
{
public override void Load()
{
Bind<IAssistanceManager>().To<AssistanceManager>();
Bind<IAssistanceAlerter>().To<AssistanceAlerter>();
Bind<ILocationHelper>().To<LocationHelper>();
Bind<IUsersRepository>().To<UsersRepository>().WithConstructorArgument("connectionString", ConfigurationManager.
ConnectionStrings[
"AppDb"].
ConnectionString);
Bind<IAssistanceRequestRepository>().To<AssistanceRequestRepository>().WithConstructorArgument(
"connectionString", ConfigurationManager.
ConnectionStrings[
"AppDb"].
ConnectionString);
}
}
}
答案 0 :(得分:2)
我遇到了类似的问题,幸运的是错误消息对我的情况更有帮助:
"NinjectControllerFactory' did not return a controller for the name 'left_bg.gif'"
"NinjectControllerFactory' did not return a controller for the name 'Content'"
我的应用程序中对'left_bg.gif'的唯一引用是在网站的主样式表中。它错误地指向了错误的文件夹。将其指向正确的文件夹可修复此错误。
Fiddler帮我解决了第二个错误。 “内容”是包含几个子文件夹(“图像”,“脚本”等)的文件夹。显然我的代码是指“/ Content / Images /”文件夹中一个不存在的图像,它在fiddler中导致500错误代码。所以我删除了对该图像的引用,Fiddler报告没有更多问题,并且错误停止了。
我可以随意复制,所以我建议使用Fiddler查看页面刷新是否有任何错误,跟踪这些错误,并将其排除在原因之外。如果你有一个名为“text”的文件夹或资源(如你报告的错误所示),可能是NinjectControllerFactory抱怨这个,就像我一样。
答案 1 :(得分:0)
我有一个类似的GetControllerInstance,我遇到了各种各样的问题。有时它会说 激活WorkflowController时出错 可以使用多个匹配的绑定。 激活路径: 1)对WorkflowController的请求
建议: 1)确保您只为WorkflowController定义了一次绑定。
有时它会说某些值不能为空...而且有时它会成功地解析控制器。