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

时间:2013-08-29 09:29:17

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

我有一个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]  

有人可以帮我找哪个问题吗?

由于

2 个答案:

答案 0 :(得分:3)

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

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

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

如果这不起作用,我会建议opening an issue at GitHub,因为这可能需要一些后退和第四次通信才能解决。如果您可以构建一个展示问题的演示项目并将其发布到GitHub或压缩并使其可供下载,那么找到解决方案还有很长的路要走。

答案 1 :(得分:1)

详细说明@ NightOwl888的回答,这对我有用 routes.IgnoreRoute("Scripts/{*pathInfo}");