Skip to content

Instantly share code, notes, and snippets.

@Bardin08
Created May 10, 2024 10:31
Show Gist options
  • Save Bardin08/7b21f0e71d21b0dc045010e9ac5f5685 to your computer and use it in GitHub Desktop.
Save Bardin08/7b21f0e71d21b0dc045010e9ac5f5685 to your computer and use it in GitHub Desktop.

Prerequisites

  • An ASP.NET Core web application with webhook endpoints ready.
  • A free or paid ngrok account.

Steps

  1. Download and Install ngrok

    • Go to the ngrok website (https://ngrok.com/) and download the version that matches your operating system.
    • Unzip the downloaded file and place the ngrok executable in a location you can easily access from your terminal or command prompt.
  2. Sign Up and Authenticate

    • Create a free ngrok account (if you haven't already) at https://dashboard.ngrok.com/signup.
    • After signing up, locate your authentication token on your ngrok dashboard.
    • Run the following command in your terminal or command prompt to authenticate your ngrok client:
      ngrok authtoken <your_auth_token>
  3. Start Your ASP.NET Core Application

    • If it's not already running, start your ASP.NET Core web application. Any IDE, or the dotnet run command can be used.
    • Find the port your ASP.NET Core application is listening on. This information is usually displayed in the console output when your app starts.
  4. Start an ngrok Tunnel

    • Open a terminal or command prompt and run the following command, replacing the port number with the actual port your ASP.NET Core application is using:

      ngrok http <your_app_port> 
      • This command will establish a secure tunnel with ngrok and provide you with two forwarding URLs, one HTTP and the other HTTPS. For example:

        Forwarding: http://1234abcd.ngrok.io -> http://localhost:5000 
        Forwarding: https://1234abcd.ngrok.io -> http://localhost:5000
        
  5. Configure Your Webhook Sender

    • Access the configuration area of the service sending the webhooks (e.g., Stripe, GitHub, Twilio, etc.).
    • Update the webhook URL to use the HTTPS URL provided by ngrok. This will ensure that webhook requests are sent to the ngrok tunnel, which will forward them to your locally running application.
  6. Test Webhook Integration

    • Trigger an event that should send a webhook request to your application.
    • Check your ASP.NET Core application's logs or debugging output to verify that the webhook request was received successfully.

Additional Notes:

  • Changing Ports: If your ASP.NET Core application changes ports, you'll need to stop the current ngrok tunnel and start a new one with the updated port number.
  • Host Header Rewriting: If your ASP.NET Core app expects specific host headers, use the -host-header option:
    ngrok http -host-header=localhost <your_app_port>
  • ASP.NET Core Configuration: If you regularly use ngrok for development, consider integrating ngrok directly into your development workflow by using middleware like the Ngrok.AspNetCore package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment