Host SignalR in IIS

会有一股神秘感。 提交于 2020-05-14 19:16:10

问题


I'm just wondering and it is hunting me for these past few days is it possible to Host a SignalR Hub in IIS? is that event possible? i found a solution called "self hosting" but it is with the help of a console application. i want to host the SignalR Hub in my IIS is that possible? can someone provide me an example regarding this?

im going to post the code for the self Hosting i thought i might help

class Program
    {
        static void Main(string[] args)
        {
            // This will *ONLY* bind to localhost, if you want to bind to all addresses
            // use http://*:8080 to bind to all addresses. 
            // See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx 
            // for more information.
            string url = "http://localhost:8080";
            using (WebApp.Start(url))
            {
                Console.WriteLine("Server running on {0}", url);
                Console.ReadLine();
            }
        }
    }
    class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR();
        }
    }
    public class MyHub : Hub
    {
        public void Send(string name, string message)
        {
            Clients.All.addMessage(name, message);
        }
    }

回答1:


Hosting SignalR in IIS is as simple as creating a website with a SignalR Hub, and then publishing it to a website within your IIS.

The SignalR Hub will then be located at http://www.yourdomain.com/

If you follow this tutorial here, you will find out what you need http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr




回答2:


The deployment for self hosting signalr server is that run the console exe by admin privilege. 192.168.1.10 is local computer IP. And other devices can connect the url by signalr.

fullIP = @"http://" + "192.168.1.10" + @":9001" SignalR = WebApp.Start(fullIP);




回答3:


Websocket support is not enabled by default on IIS. It was introduced in IIS 8, and has to be enabled from windows' optional features: https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support

Optional features -> IIS -> WWW services -> App Dev Features -> Websocket protocol

Disclaimer: I found this after asking a question about this myself, so I copied my answer from there: https://stackoverflow.com/a/61411666/4364057

In case somebody finds this after me, I'd like to provide a working answer to the question that I think is better than the excepted one.



来源:https://stackoverflow.com/questions/26418349/host-signalr-in-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!