This post is about using dev tunnel in Visual Studio to debug your web APIs. Usually when we build applications which requires a callback from an external service I used to implement a tunneling software like ngrok - one example is implementing power platform connectors. Recently Visual Studio introduced a feature called dev tunnels - here is the blog post about it - this feature helps us to debug web api endpoints with a publicly accessible endpoint.
To use this feature, first we need to enable Dev Tunnel feature from Tools > Options. Then search for keyword
Next we need to configure the User Account - I am using my GitHub account.
Now we are ready to enable dev tunnel in our applications. Create a web api project in visual studio. Modify the
launchSettings.json file under Properties folder. Add the following code under
https section of my
launchSettings.json looks like this.
Now if we run the application, we will be able to see a different URL - not the localhost one like this.
We will see this screen only one time. Once we click on continue, we will be able to access the application with the URL.
We can get the tunnel URL from using the environment variable like this -
Environment.GetEnvironmentVariable("VS_TUNNEL_URL"). If we got multiple project, the environment variable will be like this
Using dev tunnel feature will help us debugging Web APIs over public internet.