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.

Banner


Raspberry Pi CM5 - Expensive And Undocumented
27/11/2024

So the unexpected has happened - the Compute Module 5 has been launched. But it simply emphasises some problems with adopting the Pi as an IoT device.



AWS Releases Lambda SnapStart For .NET Functions
10/12/2024

Amazon has released new services for AWS Lambda SnapStart,  Amazon's performance optimization that aims to significantly improve the startup time for applications.


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Monday, 06 May 2024 )