【问题标题】:The IControllerFactory 'MvcSiteMapProvider.DI.ControllerFactoryDecorator' did not return a controller for the name 'Scripts'IControllerFactory 'MvcSiteMapProvider.DI.ControllerFactoryDe​​corator' 没有返回名称为 'Scripts' 的控制器
【发布时间】:2013-08-29 09:29:16
【问题描述】:

我有一个 MVC 4 项目,刚刚升级到 SiteMapProvider v4.0.17;自升级以来,我在编辑表单上的任何更改的回发中收到错误;菜单本身按预期工作,项目中没有其他任何更改。错误是:-

IControllerFactory 'MvcSiteMapProvider.DI.ControllerFactoryDe​​corator' 没有返回名称为 'Scripts' 的控制器

项目中唯一的“脚本”是包含 .js 文件的文件夹,所以我不确定从哪里开始查找;。异常发生在:-

>   System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.ProcessRequestInit(System.Web.HttpContextBase httpContext, out System.Web.Mvc.IController controller, out System.Web.Mvc.IControllerFactory factory) + 0x159 bytes 
System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.BeginProcessRequest(System.Web.HttpContextBase httpContext, System.AsyncCallback callback, object state) + 0x32 bytes  
System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.BeginProcessRequest(System.Web.HttpContext httpContext, System.AsyncCallback callback, object state) + 0x33 bytes  
System.Web.Mvc.dll!System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0x11 bytes   
System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x227 bytes    
System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step, ref bool completedSynchronously) + 0x9c bytes 
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x1a7 bytes  
System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0xf8 bytes  
System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr) + 0x284 bytes 
System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x6e bytes  
System.Web.dll!System.Web.HttpRuntime.ProcessRequest(System.Web.HttpWorkerRequest wr) + 0x47 bytes  
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Request.Process() + 0x188 bytes 
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Microsoft.VisualStudio.WebHost.Connection conn) + 0x66 bytes    
[Appdomain Transition]  
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(object acceptedSocket) + 0xa1 bytes   
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x3e bytes 
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes  
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes  
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x60 bytes 
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x149 bytes  
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x5 bytes 
[Native to Managed Transition]  

谁能帮我找出问题所在?

谢谢

【问题讨论】:

    标签: asp.net-mvc dependency-injection mvcsitemapprovider


    【解决方案1】:

    内部 DI 容器在您使用 MVC 注册的任何 IControllerFactory 上使用装饰器模式。在所有情况下,除了您调用/sitemap.xml 端点时,此类仅调用您注册的IControllerFactory。如果你有一个自定义的,你应该能够在 CreateController 方法中设置一个断点来找出为什么你的 IControllerFactory 在这种情况下没有返回控制器。

    如果您没有使用自定义 IControllerFactory,我冒昧地猜测这与您的路由配置错误有关,因为它正在检查不存在的名为 Scripts 的控制器。您可能需要在 RouteConfig.cs 文件顶部附近添加与此类似的行,以强制 MVC 在解析控制器时不考虑这种情况。

    routes.IgnoreRoute("Scripts/{*pathInfo}");
    

    如果这不起作用,我建议opening an issue at GitHub,因为这可能需要一些反向和第四次通信来解决。如果您可以构建一个展示问题的演示项目并将其发布在 GitHub 上或将其压缩并提供下载,那么找到解决方案将大有帮助。

    【讨论】:

    • 我有一个 nInject 控制器工厂,它具有存储库接口的绑定,但仅此而已。添加路由过滤器帮助我追踪它 - 我引用了一个丢失的 .js 文件,但报告的错误消息远没有帮助;一旦我忽略了路线,我就会收到真正的错误消息。谢谢
    【解决方案2】:

    为了解释@NightOwl888 的答案,这对我有用 routes.IgnoreRoute("Scripts/{*pathInfo}");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-23
      • 2017-06-15
      • 1970-01-01
      相关资源
      最近更新 更多