Remotely connect to .net core self hosted web api

My guess is that the issue isn’t in your controller, it is in program.cs. You need to modify the construction of your WebHost

var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://localhost:5000", "http://odin:5000", "http://192.168.1.2:5000")
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

Unless you add the UseUrls line, Kestrel isn’t going to listen outside of localhost. This makes sense, because in a normal situation Kestrel will be sitting behind a reverse proxy like IIS or NGNIX and doesn’t need to bind to external URLs.

Leave a Comment