Remotely connect to .net core self hosted web api

后端 未结 6 875
既然无缘
既然无缘 2020-12-29 02:11

I have a simple .net core web api with one action:

[Route(\"[action]\")]
public class APIController : Controller
{
    // GET api/values
    [HttpGet]
    pu         


        
6条回答
  •  天涯浪人
    2020-12-29 02:33

    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()
    .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.

提交回复
热议问题