0

在我的 MVC 项目中成功使用 kendo 有一段时间了,只是决定也添加 ImageResizer。一旦我通过 nuget 安装了 ImageResizer 以及它的 MvcRoutingShim,它就破坏了我的剑道菜单。这是一个相当基本的菜单:

Html.Kendo().Menu().Name("Menu").BindTo(Html.MvcSiteMap(provName).Provider.RootNode.ChildNodes,
                  mappings => mappings.For<MvcSiteMapNode>(binding => binding
                      .ItemDataBound((item, node) =>
                      { 
                              item.ActionName = node.Action;
                              item.ControllerName = node.Controller;
                              item.RouteValues.Add("area", node.Area);
                      })
                          .Children(node => node.ChildNodes)))
              .Render();

但是当我尝试跑步时,我得到了一个

The method or operation is not implemented

例外,具有以下堆栈跟踪:

at System.Web.HttpContextBase.get_Items()
   at ImageResizer.Plugins.MvcRoutingShim.StopRoutingRoute.GetRouteData(HttpContextBase httpContext)
   at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)
   at Kendo.Mvc.Infrastructure.Implementation.RouteDataCache.RouteDataFactory(String url)
   at Kendo.Mvc.Infrastructure.Implementation.RouteDataCache.<GetRouteData>c__AnonStorey1B.<>m__26()
   at Kendo.Mvc.Infrastructure.Implementation.NoCache.Get[T](String key, Func`1 defaultValueFactory)
   at Kendo.Mvc.Infrastructure.Implementation.RouteDataCache.GetRouteData(String key, String url)
   at Kendo.Mvc.Infrastructure.Implementation.AuthorizationContextCache.GetAuthorizationContext(RequestContext request, String controllerName, String actionName, RouteValueDictionary routeValues)
   at Kendo.Mvc.Infrastructure.Implementation.ControllerAuthorization.IsAccessibleToUser(RequestContext requestContext, String controllerName, String actionName, RouteValueDictionary routeValues)
   at Kendo.Mvc.Infrastructure.Implementation.NavigationItemAuthorization.IsAccessibleToUser(RequestContext requestContext, INavigatable navigationItem)
   at Kendo.Mvc.UI.NavigatableExtensions.IsAccessible(INavigatable item, INavigationItemAuthorization authorization, ViewContext viewContext)
   at Kendo.Mvc.UI.NavigationItemContainerExtensions.WriteItem[TComponent,TItem](TItem item, TComponent component, IHtmlNode parentTag, INavigationComponentHtmlBuilder`1 builder)
   at Kendo.Mvc.UI.Menu.<WriteHtml>c__AnonStorey71.<>m__1FC(MenuItem item)
   at Kendo.Mvc.Extensions.EnumerableExtensions.Each[T](IEnumerable`1 instance, Action`1 action)
   at Kendo.Mvc.UI.Menu.WriteHtml(HtmlTextWriter writer)
   at Kendo.Mvc.UI.WidgetBase.Render()
   at Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.Render()
   at ASP._Page_Views_Shared__Layout_cshtml.Execute() in c:\Code\StandardProject\4.4.3.0\Server\MVC\CoBRAMVC4Portal\Views\Shared\_Layout.cshtml:line 60
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.WebPages.WebPageBase.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer)
   at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
   at System.Web.WebPages.WebPageBase.Write(HelperResult result)
   at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
   at System.Web.WebPages.WebPageBase.PopContext()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)

有没有其他人让剑道与 imageresizer 一起工作?

4

1 回答 1

1

似乎 Kendo 正在从 MvcRoutingShim 请求路由数据,但提供了一个非功能性的 HttpContextBase 实例。

MvcRoutingShim 期望 context.Items 可以访问,但它在这里抛出了 NotImplementedException。

该文件位于 /Core.Mvc/StopRoutingRoute.cs 中。

    public override RouteData GetRouteData(System.Web.HttpContextBase httpContext) {
        if (httpContext.Items[_contextItemsFlag] != null)
            return new RouteData(this, new StopRoutingHandler());
        return null;
    }

将其更改为

    public override RouteData GetRouteData(System.Web.HttpContextBase httpContext) {
        try{
           if (httpContext.Items[_contextItemsFlag] != null)
                return new RouteData(this, new StopRoutingHandler());
        }catch(NotImplementedException){}

        return null;
    }

应该在不引入副作用的情况下解决问题。不幸的是,HttpContextBase 没有提供一种在没有 try/catch 的情况下“避免”NotImplementedException 的方法。类型比较会很脆弱并且会破坏单元测试,尽管如果 httpContext没有被子类化,额外的“快速退出路径”可能会在 99% 的场景中加速它。

于 2012-09-24T05:26:40.637 回答