404 /signalr/negotiate for deployed app in Azure
To find out the real cause of the issue you need to navigate to the negotiate url, and look for the response.
If the response tells you something about a 'CryptographicException: The data protection operation was unsuccessful...'. This is how to fix it.
1) Create a custom IDataProtectionProvider
2) Configure signalr
internal class MachineKeyProtectionProvider : IDataProtectionProvider{ public IDataProtector Create(params string[] purposes) { return new MachineKeyDataProtector(purposes); }}internal class MachineKeyDataProtector : IDataProtector{ private readonly string[] _purposes; public MachineKeyDataProtector(string[] purposes) { _purposes = purposes; } public byte[] Protect(byte[] userData) { //return MachineKey.Protect(userData, _purposes); return userData; } public byte[] Unprotect(byte[] protectedData) { //return System.Web.Security.MachineKey.Unprotect(protectedData, _purposes); return protectedData; }}
I use katana extension methods to bridge the IAppBuilder to IApplicationBuilder.This allows your owin middleware to connect to asp.net core. It is important to use the RunSignalr method
app.UseAppBuilder(appBuilder => { appBuilder.SetDataProtectionProvider(new MachineKeyProtectionProvider()); appBuilder.Map("/signalr", map => { var hubConfiguration = new HubConfiguration { EnableDetailedErrors = true }; map.RunSignalR(hubConfiguration); }); });