简体   繁体   中英

SignalR Self Hosted And Asp.Net MVC

I'm trying to make some self hosted SignalR app(Console). But it is not working with Asp.Net MVC 5, i was searched everything. I was working with this literally 1 day but still it is not working.

I'm using SignalR 2.4.1 both on console and web side.

The startup code on console app is;

   class startup
    {
        public void Configuration(IAppBuilder app)
        {
            var hubConfiguration = new HubConfiguration();
            hubConfiguration.EnableDetailedErrors = true;
            hubConfiguration.EnableJSONP = true;
            HubException exception = new HubException();

            //app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR(hubConfiguration);
            Console.WriteLine("hub started");
        }
    }

On console main;

  class Program
    {
        static void Main(string[] args)
        {
            string url = @"http://localhost:5693";
            var web = WebApp.Start<startup>(url);

            Console.ReadLine();
        }
    }

The Test Hub is;

    public class testHub : Hub
    {
        public void hopeWorks()
        {
            Console.WriteLine("called");
            Clients.All.Work();
            Clients.Caller.Work();
        }
    }

On the Client side is Javascript like that;

   $.connection.hub.start().done(function () {
                console.log("socket started");
            });

I was attached the message sending code to button but it didnt work, so i'm trying on console. I'm trying to call it from dev tools, and it is

$.connection.testHub.server.hopeWorks();

and nothing happens like the image shows.

I dont know what should i try else, i tried like everything. Searched on google and gone thru next pages.

Sorry for the english btw.

I fixed my problem with this. I changed the startup script like this and it works.

app.MapSignalR(hubConfiguration);

with this;

    app.Map("/signalr", map =>
            {
                HubConfiguration hcf = new HubConfiguration();
                map.RunSignalR();
            });

and now it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM