I'm testing out minimal API in C# for a small home project. I have this small (!!!!) server code :-):
var builder = WebApplication.CreateBuilder();
var app = builder.Build();
app.MapGet("/test", async () =>
{
return 1;
});
app.Run();
Locally this works just fine. I can open a browser on localhost/test and get 1 in my browser window.
However, I put it on my server running on 192.168.1.91 and now I get connection timeout.
The server application outputs:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
So its bound to localhost, should it not be bound to 0.0.0.0 or * or anything else? localhost is only for that machine?
CodePudding user response:
You have several options. Easiest one would be to just pass desired url to WebApplication.Run
method:
app.Run("http:// :5000"); //listen on all interfaces
Also I recommend investigating the hosting options: