Reputation: 14600
I'm trying to test webhooks from Stripe.com on my locahost (dev machine) using Visual Studio 2017. My site uses https. In order to test webhooks, you need a url, so on my local machine I have to install and use ngrok. Ngrok gives me a url to provide to Stripe so stripe knows where to send the post request. The problem is ngrok doesn't work with https!
I've been looking for a solution for 2 days and I've emailed ngrok to ask, they replied with
you should be able to configure VS to expose a non-encrypted port but i'm not super familiar with it in a way that I can tell you how to go about doing it. maybe the ngrok VS extension will help? https://ngrok.com/docs#visual-studio
I've already tried running the extension. No luck! All it does is open up the ngrok.exe and runs it.
So I'm trying to see if it's possible to open/expose a non-encrypted port? I assume this means a action method or controller using http and NOT https?
Or does it mean something else? Is this possible in ASP.NET MVC???
Upvotes: 3
Views: 950
Reputation: 579
I was able to get my ASP.NET Core MVC project to accept test Stripe webhooks calls this morning using ngrok in VS 2017 running on IIS Express.
I had to do two things:
Turn off app.UseHttpsRedirection()
when testing. I modified my Startup.Configure(..)
to only use HTTP redirection when not in development like this:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
// <snip>
}
else
{
// <snip>
app.UseHttpsRedirection(); // <- Moved from outside to inside else block to allow ngrok tunneling for testing Stripe webhooks
}
// <snip>
app.UseMvc();
}
Start ngrok tunneling using the non-HTTPS URL for the website. In my case, my project is configured to use the following ports:
<binding protocol="http" bindingInformation="*:64768:localhost" />
<binding protocol="https" bindingInformation="*:44358:localhost" />
So my ngrok command is this:
ngrok http 64768 -host-header="localhost:64768"
Hope this helps someone - I too struggled for awhile to get this to work.
Upvotes: 2
Reputation: 571
See my answer here: How To Disable Https in Visual Studio 2017 Web Proj ASP.NET Core 2.0
Note: If I'm wrong about there being a default unsecured URL, the question above has a solution for disabling the secured URL. I didn't try it because there was already an unsecured URL defined in my existing project (as I suspect there is with yours as well)
Upvotes: -1