1

I saw similar questions on internet but no solution helps.

I'm working on web forms.

Installed SignalR 2.2.2 and jQuery 3.3.1.

my script

<script src='<%: ResolveClientUrl("/Scripts/jquery-3.3.1.min.js") %>'></script>
<script src='<%: ResolveClientUrl("/Scripts/jquery.signalR-2.2.2.min.js") %>'></script>
<script src="/signalr/hubs"></script>

<script type="text/javascript">
    $(function () {
        // Declare a proxy to reference the hub.
        var alpha = $.connection.alphaHub;
        // Create a function that the hub can call to broadcast messages.
        alpha.client.broadcastMessage = function (message) {
            alert(message);
            //// Html encode display name and message.
            //var encodedName = $('<div />').text(name).html();
            //var encodedMsg = $('<div />').text(message).html();
            //// Add the message to the page.
            //$('#discussion').append('<li><strong>' + encodedName
            //    + '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>');
        };
        // Start the connection.
        $.connection.hub.start().done(function () {
            $('#sendmessage').click(function () {
                // Call the Send method on the hub.
                alpha.server.display($("parameters here"));

            });
        });
    });
</script>

Error is this

localhost:8888/signalr/hubs not found

Startup.cs (in the same directory as Default.aspx file)

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

Hub class

public class AlphaHub : Hub
{
    public void Display(string name, string message)
    {
        Clients.All.broadcastMessage(name, message);
    }
}

I tested same code. Built separate project and it worked there. The problem is in my current project.

Guga Todua
  • 462
  • 2
  • 11
  • 27
  • Have you tried to configure `services.AddSignalR()` inside `ConfigureServices` method? – Tân Feb 12 '20 at 13:43
  • @Tân I don't have ConfigureServices() method in my startup class. I added ConfigureServices(IServiceCollection services) method but 'services' doesn't have AddSignalR(); – Guga Todua Feb 12 '20 at 13:50
  • Oh, I see you're using `webforms` tag, I thought you're looking for asp.net mvc version. Sorry for that. In your case, here you go: [Can SignalR be used with asp.net WebForms?](https://stackoverflow.com/questions/18143599/can-signalr-be-used-with-asp-net-webforms) – Tân Feb 12 '20 at 14:02
  • @Tân I have exactly same code as in the post you linked. Difference is that author of this post has "RouteTable.Routes.MapHubs();" which is outdated and I need to use app.MapSignalR() where "app" is taken from method parameters and is of type IAppBuilder. Still no result – Guga Todua Feb 12 '20 at 14:06
  • 1
    Sorry, I'm not good at webforms but your trouble may be as same as [this question](https://stackoverflow.com/questions/17661509/signalr-and-net-client-does-not-work-on-asp-net-webforms-page) – Tân Feb 12 '20 at 14:13

0 Answers0