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); }
This tutorial shows how to host a web API inside a console application. ASP.NET Web API does not require IIS. You can self-host a web API in your own host process. New applications should use OWIN to self-host Web API.
ASP.NET Web API can be either be hosted in IIS or in a separate host process. The former approach is usually appropriate when the Web API is part of a web application and one or more web applications are going to consume it.
As the name suggests, self hosting, the Web API is hosted independently of the main/client application. So the actual Web API is hosted either in a Windows Service or a console application running on the server.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With