Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to MapSignalR causes Protocol error

this is a follow-up to my previous question here..

MVC - trouble linking to another Controller/Action

as you can see, i eventually did get my view from another controller to display in a new tab so it was working. that is until i installed SignalR. the simple version using this tutorial as a guide..

http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc

the tutorial worked fine after following the steps to create a project. the only thing i had to do to make it work was change the version of the jquery signalr javascript file to the latest (it was one i didn't have because the tutorial was written in older VS 2012).

in any case, after following the same steps for my site, i now get an error when i click the link for /SignalR/SRStart (new tab)..

Protocol error: Unknown transport

playing around i found that this only happens after calling app.MapSignalR() in the startup.cs file. can't understand why since the tutorial i followed worked fine unless it has something to do with crossing over into another controller on that link. it's in the SRStart view that i placed all the signalr connection code and callback function but i don't think it's ever reached since the page doesn't even load.

this is my code..

startup.cs

public partial class Startup
{
    public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);
        app.MapSignalR();
    }
}

hub

public class SRHub : Hub
{
    public void Send(string message)
    {
        // Call the addNewMessageToPage method to update clients.
        var conn = GlobalHost.ConnectionManager.GetHubContext<SRHub>();
        conn.Clients.All.addNewMessageToPage(message);
        //Clients.All.addNewMessageToPage(message);
    }
}

javascript in SRStart.cshtml

    $(function () {
        // Reference the auto-generated proxy for the hub.
        var conn = $.connection.sRHub;
        // Create a function that the hub can call back to display messages.
        conn.client.addNewMessageToPage = function (message) {
            if (!message.contains('[EOF]')) {
                populateStreamDialog(message);
            }
        };

        $.connection.hub.start()
            .done(function () {

            });
    });

any help would be appreciated..

like image 520
gmes29 Avatar asked May 30 '26 03:05

gmes29


1 Answers

I was able to replicate error. Problem is that /SignalR is route used by SignalR itself. By using MVC controller named SignalRController there is now conflict between SignalR and MVC causing the error. Just rename you MVC controller SignalRController (and folder containing its views) to something else...

like image 90
Michal Levý Avatar answered May 31 '26 18:05

Michal Levý