Debug Callbacks On Localhost Using ngrok

This post is about ngrok: a tool that I discovered that made my localhost development efforts when remote webhook calls are involved a lot easier*..If you ever had to debug callbacks on localhost, this post will help you too.

*note that I’m not affiliated with ngrok in any way. I am just a happy user of ngrok.

I was recently working on a 3rd party API that implemented subscription functionality to keep the API call amount of their users at bay.

The 3rd party API has a feature that sends a webhook callback when receiving new information. This prevents periodic checking for new information, thus resulting in fewer API calls.

Although it sounds awesome and benefits both the API and its users, this is hard to test when you’re developing with C# in Visual Studio – in my case a .Net Core solution featuring a web portal and API, amongst others – on your local machine.

In most cases, the combination of localhost and remote callback function calling would mean:

install IIS, a bunch of configuration that needs to be done to your project & IIS, and opening up your firewall to be able to receive the callback call.

or the alternative, deploying your stuff to a (cloud-based?) server so it could receive the incoming call, and remote debugging or checking logs.

When you normally debug callbacks getting things set up, and making your development machine visible outside of your network (going through firewalls and such).

ngrok To The Resque

Sometimes you come across a tool that makes the most difficult thing as easy as installing an app and a couple of clicks. ngrok is such a thing.It is a tool that creates an instant, secure URL to your localhost server through any NAT or firewall.

You can try out ngrok using its free tier. As soon as you fire it up, ngrok enables you to reach your localhost project via .ngrok.com.

Depending on your needs, you can also get yourself one of the paid tiers and get extra’s like custom subdomains, TLS Tunnels, IP whitelist tunnel access and reserved wildcard domains.

ngrok is awesome. But the fact that there’s a Visual Studio extension makes things even more awesome.

Are you wondering how ngrok actually makes it easy to debug callbacks for your Visual Studio solution? It detects the url and port settings from the projects in your solution and hooks up your ngrok subdomain with your localhost and port combinations. Automagically the configuration gets get set up for you! Believe me when I say that this is a true timesaver.

Using ngrok for your Visual Studio Solution

In a nutshell, here are the steps to fire up ngrok in your VS solution: