SignalR CryptographicException on AzureWebsites

前端 未结 4 783
梦谈多话
梦谈多话 2021-01-14 07:45

I got this exception with SignalR, deployed in Azure WebSites. It works fine in debug environment. It\'s SignalR 1.0.1 and I use .NET MVC and WebApi

The data         


        
4条回答
  •  我在风中等你
    2021-01-14 08:28

    For others coming to this page, I had the same issue but the solution was much simpler. As mentioned in comments above, the accepted answer is bad. Also mentioned is that SignalR defaults to use MachineKeyDataProtector for IProtectedData. MapHubs and MapConnection both call a function InitializeProtectedData which registers MachineKeyDataProtector with the dependency resolver.

    My problem was that I was mapping my SignalR routes, and THEN configuring the dependency resolver

    RouteTable.Routes.MapConnection("SomeEndpoint", "SomeEndpointUrl");
    GlobalHost.DependencyResolver = 
                         new StructureMapDependencyResolver(ObjectFactory.Container);
    

    So basically the IProtectedData resolver registration done by MapConnection -> InitializeProtectedData was getting blown away when I registered my custom resolver. Simple fix, set the resolver BEFORE mapping the connection.

    GlobalHost.DependencyResolver = 
                         new StructureMapDependencyResolver(ObjectFactory.Container);
    RouteTable.Routes.MapConnection("SomeEndpoint", "SomeEndpointUrl");
    

提交回复
热议问题