Dev Tunnels - An Alternative to Ngrok For .NET Users
Written by Nikos Vaggalis   
Monday, 06 May 2024

Dev Tunnels is a new Visual Studio option that exposes your localhost to the internet the easiest way possible. But first of all, why would you allow access from the public net to your local machine?

The reasons include to test, debug and benchmark your applications. This is especially useful for quick prototypes, proof of concept or demonstration purposes. One way to do this is to open a channel between your localhost and a public internet address so that it can be accessed by all those services.

While Ngrok is considered THE tool for creating a secure tunnel from the public web to a local machine behind a firewall or NAT, here comes another solution available from within Visual Studio 2022, Dev Tunnels.

Existing as a menu option of the IDE, with just a few clicks you get a URL that exposes your localhost online. This URL is accessible from the Internet, allowing emulators, devices, or even other devs to access your machine. Emulators is the magic word here, as Dev Tunnels' primary purpose is to lessen the hassle of testing your backend against an Android application hosted on a mobile device, local machine or an emulator. This could already have been done before the new facility, but not without the associated pain that setting up those devices involves since they have their own network stack.

To get started, you must first enable the Dev Tunnels preview feature. Use Tools/Options/Environment/Preview Features, and select the option "Enable dev tunnels for Web Applications". This will add it to the IDE menu under View/Other Windows/Dev Tunnels. You will also need to be signed into Visual Studio to create and use tunnels.

Upon opening the Dev Tunnels window, you’ll see options like choosing a name for the tunnel, specify its lifespan (persistent or temporary), and decide whether it should be private, organizational, or public.

  • Persistent is a tunnel that uses the same URL throughout its lifetime.

  • Temporary is a tunnel that uses a new URL each time that Visual Studio is started. For persistent tunnels, if the tunnel is not used for an extended period of time (weeks), the URL may change. 

  • Private means that only the signed in user has access to use that tunnel.

  • Organizational means that only users in the same organization as the account which created the tunnel can access it.

  • Public means that no authentication will be used, and anyone can access it.

Visual Studio really does makes the process too easy. But the good news do not stop there. If your haven't got Visual Studio you can still use Dev Tunnels in its CLI edition, which can run everywhere and with anything, not just .NET apps!

To use the CLI the dev tunnel service requires login for authorizing management of and access to the tunnels. You can login with a Microsoft or GitHub account as follows:

devtunnel user login

Start a tunnel at port 3000 allowing public access:

devtunnel host -p 3000 --allow-anonymous

which will show you something like :

Hosting port 3000 at https://l3rs99qw-3000. usw2. devtunnels. ms/

The displayed URI is unique to the dev tunnel port: the first component is a subdomain containing the given dev tunnel id and port number.

If the hosted port connects to a web server, then that URI can be opened directly in a browser, from anywhere. If access to the dev tunnel requires authorization, then the initial request to the URI will redirect to a login page, and return to the site after the user is authorized.

Finally you can also use the CLI as an alternative to other port-forwarding solutions.

In conclusion, DevTunnels is a great for those debugging and not only in .NET. It's also a direct competitor to Ngrok. Which will prevail?


More Information

How to use dev tunnels in Visual Studio 2022 with ASP.NET Core apps

Related Articles

Ngrok Spring Boot Starter - Tunneling The Easy Way  

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.


A Swarming Bee From Festo

The latest addition to the Festo Bionic Learning Network menagerie of bionic robots inspired by the natural world is a bee. Like the Bionic Ant from a decade ago, it has been designed n [ ... ]

Let PostgreSQL Pick An Index For You

Supabase has launched Index Advisor, a Postgres extension for recommending indexes that improve query performance, easing the burden off the developer's shoulders.

More News

raspberry pi books



or email your comment to:

Last Updated ( Monday, 06 May 2024 )