Remote connection to .net core self hosting web api

I have a simple .NET network web interface with one action:

[Route("[action]")]
    public class APIController : Controller
    {
        // GET api/values
        [HttpGet]
        public string Ping()
        {
            return DateTime.Now.ToString();
        }
    }

If I run this through the dotnet run, I get

Hosting environment: Production
Content root path: C:\Users\xxx\Documents\Visual Studio 2015\Projects\SelfHostTest\src\SelfHostTest
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

Going to the browser and entering http: // localhost: 5000 / ping results in a successful return of the current time. However, going to a remote computer (the same LAN) and trying to access the service via http: // odin: 5000 / ping , error 404 occurs. (Odin is the name of the machine running the web api in the console through the dotnet run )

Server (and client!) Firewalls are disabled. I can ping "odin" successfully.

Any ideas what a simple step I am missing here. I tried this at home and at work without success.

+4
4

, , program.cs. -

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

UseUrls, Kestrel . , Kestrel -, IIS NGNIX, URL-.

+6

, IP-. UDP- :

string localIP;
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
{
    socket.Connect("8.8.8.8", 65530);
    IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
    localIP = endPoint.Address.ToString();
}
0

, WebHost, .

var host = WebHost.CreateDefaultBuilder(args)
                .UseUrls("http://0.0.0.0:80")
                .UseStartup<Startup>()
                .Build();

API, , Docker, Windows ( \ \ )

0

"applicationhost.config". → .vs( ) → config "applicationhost.config". , name= " " Bindings node "IP/Domain" "bindingInformation", This:

<site name="project_name" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
     <virtualDirectory path="/" physicalPath="D:\Projects\project_directory" />
    </application>
    <bindings>
     <binding protocol="http" bindingInformation="*:5000:localhost" />
     <binding protocol="http" bindingInformation="*:5000:192.168.1.2" />
     <binding protocol="http" bindingInformation="*:5000:odin" />
    </bindings>
</site>

, Visual Studio .

0

Source: https://habr.com/ru/post/1655996/


All Articles