Search code examples
c#visual-studiodev-tunnels

How do you get the Dev Tunnel url from the HttpContext?


How do I get the Dev Tunnel URL from the HttpContext?

I usually got the host address like this:

var host = HttpContext.Request.Host;

But when I am using a Dev Tunnel I was expecting to get that funky URL they provide you, but I still get localhost. Please help?


Solution

  • Assuming that you are using dev tunnels in Visual Studio, you can use the Environment Variable VS_TUNNEL_URL. More info at https://learn.microsoft.com/en-us/aspnet/core/test/dev-tunnels?view=aspnetcore-7.0#tunnel-url-environment-variables