Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);             } 
like image 644
govin Avatar asked Oct 27 '14 22:10

govin


People also ask

Does Web API support self hosting?

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.

Can ASP Net Web API ability to both self hosting in IIS?

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.

What is self hosting in asp net?

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.


1 Answers

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.

like image 155
evilpilaf Avatar answered Oct 02 '22 14:10

evilpilaf