2

我将 SignalR 添加到项目中,注册了路由,一切似乎都很好接受这样一个事实,即在项目重建和页面重新加载之后,我得到了奇怪的异常:

The method or operation is not implemented.
Exception Details: System.NotImplementedException: The method or operation is not implemented.
Source Error:
Line 18:         public RouteInfo(Uri uri, string applicationPath)
Line 19:         {
Line 20:             RouteData = RouteTable.Routes.GetRouteData(new InternalHttpContext(uri, applicationPath));
Line 21:         }
Line 22:

Application_Start() 方法:

    protected void Application_Start()
    {
        RouteTable.Routes.MapHubs();
        // configure log4net
        log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(@Server.MapPath("~/log4net.config")));
        ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        if (logger.IsInfoEnabled)
        {
            logger.Info("Application_Start"); 
        }


        AreaRegistration.RegisterAllAreas();

        GlobalFilters.Filters.Add(new SitemapFilter());

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
        ConfigureJobs();
        SqlDependency.Start(Config.Instance.SubsonicConnectionString);
        PreloadTranslatableEntities();
    }

为避免这种情况,我必须返回默认页面,然后才能加载所需的页面。

堆栈跟踪:

[NotImplementedException: The method or operation is not implemented.]
System.Web.HttpRequestBase.get_CurrentExecutionFilePath() +29
Microsoft.Owin.Host.SystemWeb.OwinRoute.GetRouteData(HttpContextBase httpContext) +139
System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +233
System.Web.Routing.RouteInfo..ctor(Uri uri, String applicationPath) in d:\PGS\SWoM\Netzwerk.Web\Routing\RouteInfo.cs:20
System.Web.Routing.RouteInfoExtensions.IsRouteMatch(Uri uri, String controllerName, String actionName) in d:\PGS\SWoM\Netzwerk.Web\Routing\RouteInfoExtensions.cs:12
Netzwerk.Web.Controllers.AccountController.LogOn() in d:\PGS\SWoM\Netzwerk.Web\Controllers\AccountController.cs:49
lambda_method(Closure , ControllerBase , Object[] ) +101
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +214
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +253
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324
System.Web.Mvc.Controller.ExecuteCore() +106
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +48
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9630364
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

更新
找到了原因 - SignalR 将它自己的路由添加到 RouteTable.Routes,它抛出了 NotImplementedException。快速修复是:

 public RouteInfo(Uri uri, string applicationPath)
    {
        var routes = new RouteCollection();
        foreach (var allowedRoute in RouteTable.Routes.Where(x => x.GetType().Name != "OwinRoute"))
        {
            routes.Add(allowedRoute); 
        }

        RouteData = routes.GetRouteData(new InternalHttpContext(uri, applicationPath));
    } 
4

0 回答 0