ASP.NET Core 3.1-使用.UseUrls设置应用程序网址时,“网站无法提供安全连接”

问题描述

我正在使用“ dotnet run”运行该应用程序。如果我不使用.UseUrls()以编程方式设置url,那么它将从launchSettings.json中拾取它,并且一切正常。但是,如果我使用.UseUrls()设置相同的网址,则会在浏览器上收到以下消息。

enter image description here

代码没有错误,即两种情况都报告“正在监听:http:// localhost:6001”。有什么想法吗?

解决方法

从您的 Web.config

中删除严格的传输安全性
<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Strict-Transport-Security" 

        value="max-age=16070400; includeSubDomains" />
      </customHeaders>
    </httpProtocol>
</system.webServer>
,

我的错误-launchSettings.json使用的是https:// localhost:6001,代码使用的是http:// localhost:6001。 h!