0

I am following the basic tutorial from msdn on how to use SignalR in .Net Core apps with a js client. You can find it here: https://learn.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-2.1&tabs=visual-studio

When I try to run the app to test this simple functionality I get a 500 negotiate POST error.

I even set the log level on the connection to see more details like this

const connection = new signalR.HubConnectionBuilder()
.withUrl("/chatHub")
.configureLogging(signalR.LogLevel.Trace)
.build();

All I can get from the logs is this: image with dev tool errors

This is my backend code: The ChatHub class

using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;

namespace Tasks.WebApp.Hubs
{
    public class ChatHub : Hub
    {
        public async Task SendMessage(string user, string message)
        {
            await Clients.All.SendAsync("Message", user, message);
        }
    }
}

And the config in the Startup class:

services.AddSignalR();

And:

app.UseSignalR(routes =>
        {
            routes.MapHub<ChatHub>("/chatHub");
        });

Do you have any insight on what am I doing wrong here? I am quite new to SignalR and JS, so maybe I did something wrong there, but I tried to follow the tutorial as strict as possible.

Thanks!

qwerty
  • 11
  • 2
  • can you share your code in github or somewhere to get more details? 500 error code means, the error is at server side. you have to look server side errors for more details. – Jeeva Subburaj Sep 19 '18 at 20:52
  • my server side code is just what you can see in the turorial. Just added a class named ChatHub that inherits from Hub class in SignalR and I configured Signal in Startup file as recomended in the tutorial. So nothing new, nothing fancy. Just the code copied from the tutorial... That's why I'm wondering why do I have this issue – qwerty Sep 20 '18 at 06:23
  • You need to share the server code or we'll be left guessing. Every detail helps. – davidfowl Sep 21 '18 at 09:09
  • I've edited the question with all the backend code. Please let me know if you have a hint. – qwerty Sep 24 '18 at 08:37

1 Answers1

0

After digging through the Startup class, I found that the problem was related to the routes defined before. Found this question and the response here solved my issue.

It is mandatory to put UseSignalR before UseMvc.

qwerty
  • 11
  • 2