Web API self host - bind on all network interfaces

govin picture govin · Oct 27, 2014 · Viewed 12.1k times · Source

How do you make a Web API self host bind on all network interfaces?

I have the below code currently. Unfortunately, it binds only on localhost. So access to this server from other than localhost is failing.

var baseAddress = string.Format("http://localhost:9000/"); 
            using (WebApp.Start<Startup> (baseAddress)) 
            {
                Console.WriteLine("Server started");
                Thread.Sleep(1000000);
            }

Answer

evilpilaf picture evilpilaf · Oct 27, 2014

Just change the base address like this

        var baseAddress = "http://*:9000/"; 
        using (WebApp.Start<Startup> (baseAddress)) 
        {
            Console.WriteLine("Server started");
            Thread.Sleep(1000000);
        }

And it should bind correctlly to all interfaces.