asp.net-mvc - IControllerFactory 'MvcSiteMapProvider.DI.ControllerFactoryDecorator' 未返回名称为 'Scripts' 的 Controller

标签 asp.net-mvc dependency-injection mvcsitemapprovider

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

IControllerFactory“MvcSiteMapProvider.DI.ControllerFactoryDe​​corator”未返回名称为“Scripts”的 Controller

项目中唯一的“脚本”是包含 .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]  

有人可以帮我找到问题所在吗?

谢谢

最佳答案

内部 DI 容器在您向 MVC 注册的任何 IControllerFactory 上使用装饰器模式。在所有情况下,除了调用 /sitemap.xml 端点时之外,此类仅调用您注册的 IControllerFactory。如果您有自定义 Controller ,则应该能够在 CreateController 方法中设置断点,以找出 IControllerFactory 在这种情况下不返回 Controller 的原因。

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

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

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

关于asp.net-mvc - IControllerFactory 'MvcSiteMapProvider.DI.ControllerFactoryDecorator' 未返回名称为 'Scripts' 的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18507107/

相关文章:

javascript - Asp mvc jquery - 就地编辑

c# - 使用 MVC 站点地图时,如何更改面包屑中的父级父级?

javascript - 如何判断隐藏字段何时更改

html - 如何将验证消息 span 包装在 div 中并根据验证渲染容器?

asp.net - 在 asp.net mvc 中从母版页 View 中查找 Controller 名称的更好方法

entity-framework - 从 Entity Framework 上下文中删除失败的更改

java - 为什么 Dagger 注入(inject)具体类?

PHPUnit 依赖注入(inject)到测试用例中

asp.net-mvc-4 - MvcSiteMap 提供程序中的自定义属性