Search code examples
c#iissignalrsignalr-hub

Host SignalR in IIS


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);
        }
    }

Solution

  • 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