0

Disclaimer: I know there are a few variants of this problem on this site but none of them helped me solved my problem -- Believe me I'd be more than happy if I didn't have to post another one.

Follow-up to this question: Ping not working between Laptop and Phone even with firewall rules and without firewall

I am running a Web API on my Windows Laptop which is an ASP.NET WebAPI running on Kestrel webserver. I am failing to access this api from my Android Phone.

Both my Laptop (192.168.178.44) and Phone (192.168.178.69) are in the same local net. Ping works between the two devices.

This is the webserver running on my laptop:

enter image description here

Running localhost:5000/api/salt/a on my laptop works perfectly fine. However, entering http://192.168.178.44:5000/api/salt/a in both Chrome and Firefox on my phone results in ERR_CONNECTION_TIMED_OUT.

I thought it might be the firewall but the issue persists even after disabling it, just as was the case in my other question linked above.

What else can I do to try and fix this problem?

1 Answers1

0

As @Robert pointed out in the comment "A server running on localhost is by definition only accessible on the same device."

So the solution is to make the server listen for example on wildcard instead of localhost.

In my case that meant adding a single line of code to the Web HostBuilder in ASP Web API:

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseUrls("http://*:5000/;https://*:5001");
                    webBuilder.UseStartup<Startup>();
                });