如何配置Visual Studio 2017以在ASP.Net MVC https站点中公开未加密的端口

问题描述 投票:3回答:2

我正在尝试使用Visual Studio 2017在我的locahost(开发机器)上测试来自Stripe.com的webhooks。我的网站使用https。为了测试webhook,你需要一个url,所以在我的本地机器上我必须安装并使用ngrok。 Ngrok给了我一个提供给Stripe的网址,因此条纹知道发送帖子请求的位置。问题是ngrok无法使用https!

我一直在寻找解决方案2天,我已经通过电子邮件发送了ngrok来询问,他们回答说

你应该能够配置VS以暴露一个非加密的端口,但我不是很熟悉它,我可以告诉你如何去做。也许ngrok VS扩展会有所帮助? https://ngrok.com/docs#visual-studio

我已经尝试过运行扩展程序。没运气!它只是打开ngrok.exe并运行它。

所以我试图看看是否可以打开/暴露一个非加密端口?我认为这意味着使用http和NOT https的动作方法或控制器?

或者它意味着什么呢?这可能在ASP.NET MVC中???

c# asp.net-mvc visual-studio https ngrok
2个回答
2
投票

我能够让我的ASP.NET Core MVC项目在今天早上使用在IIS Express上运行的VS 2017中的ngrok接受测试Stripe webhooks调用。

我不得不做两件事:

  1. 测试时关闭app.UseHttpsRedirection()。我修改我的Startup.Configure(..)只在不在开发中时使用HTTP重定向,如下所示: 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(); }
  2. 使用网站的非HTTPS URL启动ngrok隧道。就我而言,我的项目配置为使用以下端口: <binding protocol="http" bindingInformation="*:64768:localhost" /> <binding protocol="https" bindingInformation="*:44358:localhost" /> 所以我的ngrok命令是这样的: ngrok http 64768 -host-header="localhost:64768"

希望这有助于某些人 - 我也有一段时间难以让这个工作。


-1
投票

在这里看到我的答案:How To Disable Https in Visual Studio 2017 Web Proj ASP.NET Core 2.0

注意:如果我错误地存在默认的不安全URL,则上述问题有解除禁用安全URL的解决方案。我没有尝试过,因为在我现有的项目中已经定义了一个不安全的URL(因为我怀疑还有你的URL)

Just use the established unsecured URL instead of the secured one.

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.