I want to send data using SignalR from a web app hosted in Azure to the browser. I have a simple test app that works fine running locally in Visual Studio 2015 using IIS Express, but when I publish to my Azure tenant it fails.
I created a SPA in Visual Studio 2015 running the dnx46 framework. I turned Web Sockets on in my tenant. The browser pops up the error "Error: Error during negotiation request."
The browser console has the following 500 error
jquery.js:8630 GET http://skywalkerpoc.azurewebsites.net/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22probehub%22%7D%5D&_=1457633993462 500 (Internal Server Error)
You'll need to turn on some SignalR tracing server-side and examine what comes out of there. See the SignalR docs on www.asp.net for info about that.
Also, it's worth trying to disable websockets to see if long polling works. If so then you have a websocket issue. If it doesn't work then you can focus more on SignalR and how it's running.
Does the generated Javascript hubs file look the same in both environments (if it's having a problem in the production environment that may also point you in the right direction)?
I disabled web sockets and it didn't work.
The hubs files look the same in both environments. In Azure, when I step through it in Chrome, it creates the hub proxies and registers them. At that point, it should call the function makeProxyCallback(hub, callback) to call the client hub method, but it never gets there and throws the following:
if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
}
In my Index.cshtml file:
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/signalr/jquery.signalR.js"></script>
<script src="signalr/hubs"></script>
This is the logging to the browser console:
[10:49:00 GMT-0800 (Pacific Standard Time)] SignalR: Client subscribed to hub 'probehub'. jquery.signalR.js:81:17
[10:49:00 GMT-0800 (Pacific Standard Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22probehub%22%7D%5D'. jquery.signalR.js:81:17
no element found negotiate:1:1
[10:49:07 GMT-0800 (Pacific Standard Time)] SignalR: Stopping connection. jquery.signalR.js:81:17
I am facing the same issue. I've created a very simple sample chat web application using VS2015, ASP.Net 5 which works on my local PC. However when I publish to azure web app (using VS2015 ), I receive the "Error during negotiation request" error. I have already tried all suggestions listed above. Interestingly, when I publish (using VS2015) another sample project made using a MVC5 to azure, it works in azure.
I would appreciate any help with getting this to work => ASP.Net 5, * MVC6 *, SignalR2 web app in Azure. Nothing fancy, just a simple chat app.
Hello,
I have then same problem. For IIS Express or "web", it works very well. In Azure :
Error 500 when negociate Or
Path for all my routes are started with "signalR".. and this causes an erreur for all loads and routes (css, js...)
it's ok to me. I Created a new provider for DataProtected. Non Crypting for now, for test. But is the solution.
using Microsoft.Owin.Security.DataProtection;
.
.
.
appBuilder.SetDataProtectionProvider(new MachineKeyProtectionProvider());
.
.
.
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;
}
}
@jelubrlu I tried your solution, but it doesn't work for me...
I still have the same problem
Edit: probably I did something wrong last time. this workaround is working for me too. But what are the security issues with this?
@jelubrlu Thanks this workaround is working for me
@jelubrlu Thanks - this is working for me.
But - what have I just did? Will this give security issues?
Hi.
Thanks for the solution.
Why in azure exists this problem? I tried your solution, and it's working now. In my Iss Express i don't need to use SetDataProtectionProvider in AppBuilder.
Why?
Well, this worked for me. I don't know if it's secure though.
I've struggled with this 500 (Internal Server Error) when our app using SignalR was published on Azure. Everything was fine on IISExpress or local machine. Then I realized that the data protection provider (throwing error) is using some local resources (keys or so from the local machine) and the IIS app pool in Azure is running with the ApplicationPoolIdentity.
So, changing the account for application pool to more priviledged local account solved the problem completely.
Data protection is using machine key to do encryption and decryption. It's possible to configure machineKey in the web.config file. If you are running just one server autogenerate is probably your best bet.
Using the MachineKeyDataProtector worked for me to.
I'm still struggling - when I deploy to Azure app service the hub connection fails with a negotiation error (web app works locally).
Can anyone point me to a sample asp.net core (sdk ...3131, .net461) signalr (2.2.1) app that runs in azure please?
Hope someone can help, thanks
--R
I have this sample https://github.com/moozzyk/SignalRTest that is running on Azure here: http://testsignalrchat.azurewebsites.net/echo.html. I did not have to do anything special to make it run on Azure. It's a stock chat sample that also has a raw connection mapped to "/echo".
Thx @moozzyk - I'll check it out 馃憤
A quick scan reveals a couple of obvious differences:
.NET 452, I'm using 461, any particular reason for using 452?
(I noticed in a recent blog post that @shanselman favoured 452 over 461. I don't understand why)
You're using the built in proxy, I'm not.
Couple of things for me to look at. Thx
There shouldn't be any difference between net452 and net461 - these are in place updates that should not have breaking changes. net452 in my project came just from the template and I simply did not re-target the project after I created it.
@moozzyk Your test proj works fine in my azure - yay :) but there's no authentication.
When I wizard an app that has user account authentication, but uses your example SignalR code, I get the same hub connection fail.
Can anyone point me to a sample asp.net core (sdk ...3131, .net461) signalr (2.2.1) app, with user accounts (and authentication), that runs in azure please?
Hope someone can help, thanks
--R
Do you have any stacktrace or something? Isn't the authentication using a database to store the users? If it is - have you set up the sql server and made sure that the application is able to connect to this database (a.k.a. is your connection string correct?)
Thx for the suggestion @moozzyk, but the registration of users and login all works fine. The app works, but signalr doesn't, if that makes sense.
I added your signalr code to the index.cshtml page of my test app so it runs when the page loads (no logged in user) but I get the same behaviour when I authenticate and hit index.cshtml again.
When I run locally on my laptop it works, and when I run from azure it fails.
I'm happy to mail a URL to demo if any obi-wan can help pls?
`
```
// Start the connection.
$.connection.hub.start(config)
.done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
})
.fail(function () {
alert("hub start fail!");
});
````
Could it be a CryptographicException during the negotiation?
(This describes my problem: http://stackoverflow.com/questions/36475209/signalr-2-fails-on-azure)
Anyone got a working example please?
Thanks for reading
--R
It could be many things. I think you just need to somehow debug/trace to see what's happening on the server (i.e. the exception and the stack trace). What is the first request that fails? Is it negotiate? Because if it is negotiate you can just send the request from the browser to repro the issue. Maybe you can create an isolated environment and turn on displaying exception details? Otherwise you don't know what you are looking for.
@moozzyk thx for all your help - I need to do some more reading but calling UseAesDataProtectorProvider() before MapSignalR() (instead of after) seems to have fixed my problem.
I'm quite confused by it all, SignalR: easy, Azure deployment: easy, but my scenario (which I don't think is atypical: New web app with individual user account auth and SignalR) seems to have been tricky.
(I know all this is in a state of flux.)
Thanks for taking the time to reply to me, it was a great help.
--R
@rowlandg I have the same issue - I think this is the solution: Azure WebApps is configured to not load user profile by default, this causes the exception. In Azure App Settings, create an Application Setting called WEBSITE_LOAD_USER_PROFILE and set it to 1. This will load the user profile.
Most helpful comment
Hi.
Thanks for the solution.
Why in azure exists this problem? I tried your solution, and it's working now. In my Iss Express i don't need to use SetDataProtectionProvider in AppBuilder.
Why?