Securely Share Your Local ASP.NET Core Development Server with TryCloudflare
Sharing your local ASP.NET Core development server can be a very useful way of obtaining feedback, testing webhook integrations, and facilitating collaboration during development. One method of sharing a development server is to use ngrok, however a TryCloudflare tunnel can also be used to create a temporary publicly accessible URL to the web application.
What is TryCloudflare?
TryCloudflare is a service built upon Cloudflare Tunnels intended to compete with ngrok. It generates a public preview URL which will direct traffic to your local development web server for a response. To use this service is requires running the Cloudflare Tunnel daemon (cloudflared) on your machine.
Installing cloudflared
The method used to install cloudflared will depend on the operating system.
For macOS systems, cloudflared
can be installed by using Homebrew with the following command:
bash brew install cloudflare/cloudflare/cloudflared
For Windows systems, cloudflared
can be installed by using winget with the following command
winget install cloudflared
Now that cloudflared
is installed it can be used to start a Cloudflare Tunnel.
Starting a Cloudflare Tunnel with TryCloudflare
To start the Cloudflare Tunnel we will need to know the URL to the local development server, for an ASP.NET Core web app this will usually be similar to https://localhost:5000
. You can find this in the console output when starting the web application.
info: Microsoft.Hosting.Lifetime[14]Now listening on: https://localhost:7155
info: Microsoft.Hosting.Lifetime[14]Now listening on: http://localhost:5155
info: Microsoft.Hosting.Lifetime[0]Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]Hosting environment: Development
As you can see from the output above, in my example the web application was available on https://localhost:7155
. Now that we have the local development URL, we can start the Cloudflare Tunnel using TryCloudflare and make our local development app available publicly.
The tunnel can be started by using the following command:
cloudflared --url https://localhost:7155
The randomly generated public URL can be found in the console output.
2023-06-04T13:25:51Z INF Thank you for trying Cloudflare Tunnel. Doing so, without a Cloudflare account, is a quick way to experiment and try it out. However, be aware that these account-less Tunnels have no uptime guarantee. If you intend to use Tunnels in production you should use a pre-created named tunnel by following: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps
2023-06-04T13:25:51Z INF Requesting new quick Tunnel on trycloudflare.com...
2023-06-04T13:25:53Z INF +--------------------------------------------------------------------------------------------+
2023-06-04T13:25:53Z INF | Your quick Tunnel has been created! Visit it at (it may take some time to be reachable): |
2023-06-04T13:25:53Z INF | https://infant-containing-acne-pictures.trycloudflare.com |
2023-06-04T13:25:53Z INF +--------------------------------------------------------------------------------------------+
2023-06-04T13:25:53Z INF Cannot determine default configuration path. No file [config.yml config.yaml] in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp]
2023-06-04T13:25:53Z INF Version 2023.5.0
2023-06-04T13:25:53Z INF GOOS: windows, GOVersion: go1.19, GoArch: amd64
2023-06-04T13:25:53Z INF Settings: map[ha-connections:1 protocol:quic url:https://localhost:7155]
2023-06-04T13:25:53Z INF cloudflared will not automatically update on Windows systems.
2023-06-04T13:25:53Z INF Generated Connector ID: e7e6b352-e265-4b02-8d03-2fc1f448da7f
2023-06-04T13:25:53Z INF Initial protocol quic
2023-06-04T13:25:53Z INF cloudflared does not support loading the system root certificate pool on Windows. Please use --origin-ca-pool <PATH> to specify the path to the certificate pool
2023-06-04T13:25:53Z INF Starting metrics server on 127.0.0.1:55881/metrics
2023-06-04T13:25:53Z WRN Your version 2023.5.0 is outdated. We recommend upgrading it to 2023.5.1
2023-06-04T13:25:54Z INF Registered tunnel connection connIndex=0 connection=3fd61b79-e8fb-473c-a763-bdfd419caafb event=0 ip=198.41.192.57 location=LHR protocol=quic
In the example output above, you can see that generated public URL was https://infant-containing-acne-pictures.trycloudflare.com
. This means any requests to https://infant-containing-acne-pictures.trycloudflare.com
will be served by the web application running on the local development server.
Summary
Sharing a local development server can be useful when creating webhook integrations, or when you want to share local changes with someone for feedback. cloudflared
can be used with the TryCloudflare service to create a quick tunnel with a randomly generated public URL which can be shared as required.