I use SignalR 2.0.0 Win2012 iis8
After using latest 2.0.0 version in previous version the error not occurred. i am received that error: "Failed to ping server". but i am still connected.
why i receive the above error?
what i need to do for resolve the problem?
Thanks
my part code of client:
function connect(host)
{
var hubConnection = $.hubConnection.('');
hubConnection.url = host;
hubConnection.start()
.done(open)
.fail(error);
}
function open()
{
console.log('success')
}
function disconnect()
{
var self = this,
hubConnection = $.hubConnection("");
console.log('disconnect ')
hubConnection.stop(true, true);
}
function error(error)
{
console.log('error')
}
if you need more details for answer do not hesitate to ask.
Related
I have setup a console application that just runs a loop and emits a message using Signal R. The client that is listening is an angular application.
When I run locally, (Both the Console application and the Angular Site) it works fine. However, when I run my console application in my Vagrant VM (Ubuntu HOST), then I get an all too familiar error message such as the following:
GET http://localhost:12345/signalr/negotiate?clientProtocol=1.5&userId=12345&connectionData=%5B%7B%22
name%22%3A%22testem
itter%22%7D%5D&_=1446565284280 500 (Internal Server Error)
I have ran into issues similar to this before (maybe this exact one) so here are some initial details
The code I have looks like the following:
namespace test
{
public class Program
{
public static void Main(string[] args)
{
try
{
using (WebApp.Start<EmmitStartup>("http://*:12345"))
{
Console.Out.WriteLine("Emmit started on http://*:12345");
IEmitterFactory factory = new EmitterFactory();
while (true)
{
Thread.Sleep(5000);
ITestEmitter emitter = factory.Create((ctx) =>
{
return new TestEmitter(ctx);
});
emitter.SayHello();
emitter.Echo("Hello World:" + DateTime.Now);
}
}
}
catch (Exception e)
{
Console.Out.WriteLine(e.Message);
Console.Out.WriteLine(e.StackTrace);
Console.ReadLine();
}
}
}
public class TestEmitter:Emitter,ITestEmitter
{
public TestEmitter(IEmitterContext emitterContext) : base(emitterContext)
{
}
public TestEmitter(IEmitterContext emitterContext, EmitterModel model) : base(emitterContext, model)
{
}
public TestEmitter(IDictionary<string, object> model) : base(model)
{
}
public void SayHello()
{
EmitterContext.Clients.All.onSayHello();
}
public void Echo(string message)
{
EmitterContext.Clients.All.onEcho(message);
}
}
public interface ITestEmitter
{
void SayHello();
void Echo(string message);
}
public class EmmitStartup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(CorsOptions.AllowAll);
app.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule());
var config = new HubConfiguration()
{
EnableDetailedErrors = true,
EnableJavaScriptProxies = true,
EnableJSONP = true
};
map.RunSignalR(config);
});
}
}
}
There are no exception or error logs being thrown on the server.
I have enabled CORS in SignalR
I have tried to use both http://*:12345 and http://localhost:12345 and http://0.0.0.0:12345
The Emmit library is just syntactic sugar and makes direct pass through to SignalR (I have tried same exact with SignalR directly.
I have tried different combinations of enabling/disabling EnableJSONP
I know SignalR is working and accessible through the VM because I can hit http://localhost:12345/signalr/hubs and it shows proxy file.
I have setup port fowarding to the Vagrant VM for port 12345
I have disabled firewall on VM HOST (Ubuntu) with sudo ufw disable
The code for the client looks like the following:
var emmitProxy = null;
Emmit.createProxy({
emitter:'testEmitter',
path:'http://localhost:12345/signalr',
listeners:{
'onSayHello':function(){
$log.info('onSayHello triggered')
},
'onEcho':function(message){
$log.info(message);
}
},
onError:function(){
//an error occured
$log.error('testEmitter:onError');
},
onDisconnected:function(){
//proxy was disconnected
$log.debug('testEmitter:onDisconnected');
},
queryParams:{
userId:'12345' //optional
}
}).then(function(newProxy){
emmitProxy = newProxy;
});
UPDATE
I enabled logging and here is the output. Before another person recommends I enable CORS, I don't think that CORS is the issue, I think its just the cascading impact of something else that is having an issue.
UPDATE
I have ran this in multiple environments with the following results:
Ran in Docker container on Vagrant VM (Ubuntu) - ERROR OCCURS
Ran directly on Vagrant VM (Ubuntu) - ERROR OCCURS
Deployed in Docker Container to Tutum - ERROR OCCURS
Ran directly through Visual Studio on Windows - EVERYTHING WORKS
Ran directly on Mac oSX (on Mono obviously) - EVERYTHING WORKS
I have added the following IHubPipelineModule
public class ErrorHandlingPipelineModule:HubPipelineModule
{
public override Func<HubDescriptor, IRequest, bool> BuildAuthorizeConnect (Func<HubDescriptor, IRequest, bool> authorizeConnect)
{
try
{
Console.Out.WriteLine ("BuildAuthorizeConnect");
return base.BuildAuthorizeConnect (authorizeConnect);
}
catch (Exception exception)
{
Console.Out.WriteLine ("AuthorizeConnect Failure");
Console.Out.WriteLine(exception.Message);
}
return base.BuildAuthorizeConnect(authorizeConnect);
}
protected override void OnAfterDisconnect (IHub hub, bool stopCalled)
{
try
{
Console.Out.WriteLine ("OnAfterDisconnect");
base.OnAfterDisconnect (hub, stopCalled);
Console.Out.WriteLine ("After OnAfterDisconnect");
}
catch (Exception exception)
{
Console.Out.WriteLine ("AfterDisconnect Failure");
Console.Out.WriteLine(exception.Message);
}
}
protected override bool OnBeforeDisconnect (IHub hub, bool stopCalled)
{
try
{
Console.Out.WriteLine ("OnBeforeDisconnect");
return base.OnBeforeDisconnect (hub, stopCalled);
}
catch (Exception exception)
{
Console.Out.WriteLine ("BeforeDisconnect Failure");
Console.Out.WriteLine(exception.Message);
}
return base.OnBeforeDisconnect (hub, stopCalled);
}
public override Func<IHub, System.Threading.Tasks.Task> BuildConnect(Func<IHub, System.Threading.Tasks.Task> connect)
{
try
{
Console.Out.WriteLine("BuildConnect");
return base.BuildConnect(connect);
}
catch (Exception exception)
{
Console.Out.WriteLine(exception.Message);
}
return base.BuildConnect(connect);
}
protected override void OnAfterConnect(IHub hub)
{
try
{
Console.Out.WriteLine("OnAfterConnect");
base.OnAfterConnect(hub);
}
catch (Exception exception)
{
Console.Out.WriteLine ("OnAfterConnect Failure");
Console.Out.WriteLine(exception.Message);
}
}
protected override bool OnBeforeConnect(IHub hub)
{
try
{
Console.Out.WriteLine("OnBeforeConnect");
return base.OnBeforeConnect(hub);
}
catch (Exception exception)
{
Console.Out.WriteLine ("OnBeforeConnect Failure");
Console.Out.WriteLine(exception.Message);
}
return base.OnBeforeConnect (hub);
}
}
And when I check my logs, the only logs that are printed out are the following:
BuildConnect
BuildAuthorizeConnect
UPDATE
I am not sure if this will be relevant or how I may have missed it, but I checked the response from the 500 and have posted it to Here
It looks like it is showing it is related to Improperly protected user's key pairs in '/root/.config/.mono/keypairs'.
Also, I am not sure if this link contains sensitive information. If somebody can let me know if it does, I would appreciate it.
I did a minimal amount of research thus far and came across SignalR.Owin works under Windows but returns 500 for Mono on Linux
When I check the Network tab for the negotiate request, I get the following
** Headers**
Remote Address:127.0.0.1:12345
Request URL:http://localhost:12345/signalr/negotiate?clientProtocol=1.5&userId=12345&connectionData=%5B%7B%22name%22%3A%22testemitter%22%7D%5D&_=1446964166640
Request Method:GET
Status Code:500 Internal Server Error
HTTP/1.1 500 Internal Server Error
Access-Control-Allow-Origin: http://localhost:8100
Access-Control-Allow-Credentials: true
X-Content-Type-Options: nosniff
Content-Type: text/html
Server: Mono-HTTPAPI/1.0
Date: Sun, 08 Nov 2015 06:30:28 GMT
Connection: close
Transfer-Encoding: chunked
Accept:text/plain, */*; q=0.01
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:JSESSIONID.ae4b31f4=aqpz31hevinaauwftyijure; JSESSIONID.26c95422=1m32u58exuvjz5jrojszqziqh; JSESSIONID.3fd19426=iv9fawaej3nt14yzcruj45si5; JSESSIONID.8868ba42=1gh4w06alx8ehuuj1adr5w8y8; JSESSIONID.947cfb91=nyxfrp6u0pny1sl8gwlouprh4; screenResolution=1280x800
Host:localhost:12345
Origin:http://localhost:8100
Pragma:no-cache
Referer:http://localhost:8100/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
Although your app contains app.UseCors(CorsOptions.AllowAll), the original error message is pretty clear that this is a CORS issue.
The Origin URL (http://localhost:8100) is different than the SignalR server URL (http://localhost:12345) With CORS, the scheme, domain, and port have to match; in this case, the port is different.
Here's what to do:
Ensure the URLs are actually correct and are what you expect. (Port 8100)
Capture the HTTP traffic on the client. You can do this using Fiddler or a similar tool. You can also just use the "network" tab of the chrome debugger.
Verify that the initial page load actually contains the CORS header. You should see Access-Control-Allow-Origin: in the response header. Based on how you've configured it, the value should be: *
...I believe the issue here is that you've enabled CORS on the SignalR server (Port 12345), but CORS needs to be enabled on your webserver. (Port 8100)
EDIT
The original question was edited. With the addition of the HTTP headers, the error message has changed from a CORS issue to a 500 error.
CryptographicException: Improperly protected user's key pairs in '/root/.config/.mono/keypairs'.
...
CryptographicException: Data protection failed.
System.Security.Cryptography.ProtectedData.Protect (System.Byte[] userData, System.Byte[] optionalEntropy, DataProtectionScope scope) [0x00000]
Microsoft.AspNet.SignalR.Infrastructure.DefaultProtectedData.Protect (System.String data, System.String purpose) [0x00000]
I did a minimal amount of research thus far and came across SignalR.Owin works under Windows but returns 500 for Mono on Linux
The GitHub Issue that you linked to exactly matches what you've described. Since it's marked closed, the obvious question is to see if what's described in the ticket also applies to you. From the ticket:
davidfowl commented on May 22, 2013 -
I just fixed the build in the dev branch yesterday. It requires mono 3.0.10 to run and works fine now.
So, verify two things:
The version of Mono installed on your server. The Ticket says Mono 3.0.10 is needed. What version do you have?
SignalR needs to include the changes. It's one or both of these. Ensure that whatever version of SignalR you're using includes these changes:
Change 1
Change 2
Lastly, if you need to, you do have the option of injecting your own version of SignalR.Core/Infrastructure/DefaultProtectedData.cs. You can simply set it in the OWIN pipeline. From the SignalR Source Code:
// Use the data protection provider from app builder and fallback to the
// Dpapi provider
IDataProtectionProvider provider = builder.GetDataProtectionProvider();
IProtectedData protectedData;
See the selected answer for insight into the problem and potential solution.
I solved the problem by making sure I had a version of Mono 3.0.10 or later. I am using Docker, so this was as easy as updating my FROM statement in my Dockerfile.
I have a solution in which i am using SignalR. There is a Hub in one of the projects and SignalR.Client in the others that are connecting to that Hub.
This solution is hosted on two servers, and I have a strange problem. In one server everything works fine, but in the other i get an 404 not found error when I am trying to establish the connection from the SignalR.Client.
Hub Code:
public class GlobalHub : Hub
{
public void Hello()
{
Clients.All.hello();
}
public void Notify(string user,NotificationViewModel model)
{
Clients.Group(user).notify(model);
}
public override System.Threading.Tasks.Task OnConnected()
{
string name = Env.UserId().ToString();
Groups.Add(Context.ConnectionId, name);
return base.OnConnected();
}
}
Global.asax Hub Map:
var hubConfiguration = new HubConfiguration
{
EnableDetailedErrors = true,
EnableJavaScriptProxies = true
};
RouteTable.Routes.MapHubs("/signalr",hubConfiguration);
The connection attempt:
string portal = CommonHelper.GetPortalUrl("user");
if(portal.Contains(":50150"))
{
portal = portal.Replace(":50150", "");
}
var connection = new HubConnection(portal+"signalr",false);
IHubProxy myHub = connection.CreateHubProxy("GlobalHub");
connection.Start().Wait();
myHub.Invoke("Notify", userID.ToString(), result2);
I am pretty sure that my connection url is correct, I checked it 50 times.
Error occurs on this line:
onnection.Start().Wait();
SS of Error:
Thanks
The problem may be that when hosting a SignalR project on two servers, clients connected to one can only be connected to other clients connected to the same server. That is because SignalR doesn't automatically broadcast a message through all servers.
http://www.asp.net/signalr/overview/performance/scaleout-in-signalr
Try have a look here and I hope it is helpful to you. One of the proposed solution is to use the Redis Pub/Sub (http://redis.io/topics/pubsub) solution, or Azure Service Bus (http://azure.microsoft.com/en-us/services/service-bus/) - both of whom are use as a backplane (when a server receives a message, it is broadcast to all of them and the one that needs it can use it).
Thanks I solved the problem. It turned out that it was a problem with the server. The server itself couldnt recognize that url (throws 404 on the url).
After that problem was fixed, SignalR started working
I am encountering an issue when attempting to rename a SignalR hub. Please note that I'm not using generated proxies with SignalR.
I have a SignalR Hub that was previously defined as:
[HubName("WidgetHub")
public WidgetHub : Hub
{
...
}
Creating the proxy on the client is done using this code:
this.proxy = connection.createHubProxy('WidgetHub');
this.proxy.on('WidgetUpdated', function() {
$rootScope.$emit('refreshWidget');
});
return connection.start().then(function(connectionObj) {
return connectionObj;
}, function(error) {
console.log(error)
return error.message;
});
};
This is working correctly, however, I now want to rename the hub. I figured I could easily do this by specifying a new name in the [HubName()] attribute:
[HubName("CloudHub")
public WidgetHub : Hub
{
...
}
And the updating the client proxy creation to reference the new hub name:
this.proxy = connection.createHubProxy('CloudHub');
However, when I do this, the client connection errors out with the following message being return:
Error: SignalR: Connection must be started before data can be sent.
Call .start() before .send()
I suspected that I have a caching issue somewhere, because even after specifying the new hub name, if I reference the old hub name, it works correctly.
I have tried cleaning up IIS and all the browser caches, but to no avail. Is there something else that I'm missing here on why changing the HubName attribute is not working for me?
try to make your hubName as follows
[HubName("cloudHub")]
public WidgetHub : Hub
{
...
}
and create proxy like
this.proxy = connection.createHubProxy('cloudHub');
then try to start hub by calling method Start();
$.connection.hub.start().done(function () {
....
....
});
I have an MVC 5 website running signalR 2.1.0 using Windows Authentication. Because I'm using windows auth login/logout is handled automatically by IIS. Occassionally I'm getting a 403 error saying "Unrecognized user identity. The user identity cannot change during an active SignalR connection." This doesn't happen all the time, and I can't seem to find a pattern to when it does and does not work. Has anyone else encountered this?
Here is the code on the view:
<script type="text/javascript">
$(document).ready(function() {
SignalRSetup();
});
function SignalRSetup() {
// Declare a proxy to reference the hub.
var hub = $.connection.tokenRequestHub;
// Create a function that the hub can call to broadcast messages.
hub.client.updateFromService = function(tokenRequestID, message, success) {
var msg = "Token Request ID {0} => {1}".format(tokenRequestID, message);
var notyType = (success) ? 'success' : 'error';
noty({ text: msg, type: notyType, timeout: 2000 });
if (success) {
refreshGrids();
}
};
$.connection.hub.start();//this is where it errors!
}
</script>
Any help would be greatly appreciated.
I think I fixed the issue by adding an [Authorize] attribute to my Hub class. It's only been a few hours, but my SignalR powered page is behaving much better.
What worked for me was to disable Anonymous Authentication in the IIS settings.
Another solution I found other than disable Anonymous Authentication is to add
GlobalHost.HubPipeline.RequireAuthentication();
to public void Configuration(IAppBuilder app) method in the Startup class.
i was trying signalR hubs trough their sample at https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs.
i managed to create an mvc 4 asp.net app using their sample for asp.net, BUT when i try to debug the console app program :
public class Program
{
public static void Main(string[] args)
{
// Connect to the service
var hubConnection = new HubConnection("http://localhost/5623");
// Create a proxy to the chat service
var chat = hubConnection.CreateHubProxy("chat");
// Print the message when it comes in
chat.On("addMessage", message => Console.WriteLine(message));
// Start the connection
hubConnection.Start().Wait();
string line = null;
while((line = Console.ReadLine()) != null)
{
// Send a message to the server
chat.Invoke("Send", line).Wait();
}
}
}
it send me an exception at hubConnection.Start().Wait(); saying {"The remote server returned an error: (500) Internal Server Error."}.
i think it has something to do with the http://localhost/5623, i tried http://localhost/5623/Home and http://localhost/5623/Home/Chat i got {"The remote server returned an error: (404) Not Found."} error instead.
How can i solve this please.
Thank you.