Search code examples
c#asp.netasp.net-web-api2self-hosting

Web API self host - bind on all network interfaces


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

Solution

  • 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.