Expose .NET Core WebAPI from VSCode on Network on WSL2

676 views Asked by At

I develop in WSL2. I have a .NET Core web API, that I want to to run from a VS Code debug session, that I want to access from another machine, to trigger my breakpoint (the other machine adds some additional headers). I can only seem to access this from my machine under localhost. I cannot access this from another machine on the network as say - http://mymachinename.domain.com/api/MyEndpoint.

However, we can do this while running under Windows, with UseUrls in Program.cs, but this does not seem to work while hosted in WSL2.

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

}

How do I make accessible on our network while hosted in WSL2?

1

There are 1 answers

2
Old Geezer On

Your WSL instance has a separate IP address. To find out run:

hostname -I

Your .NET Core code should just specify http://localhost:5000.