Asp.net核心HttpsRedirectionMiddleware无法确定要重定向的https端口

时间:2018-12-11 12:25:30

标签: asp.net-core windows-services asp.net-core-mvc asp.net-core-2.2

我正在尝试在Windows服务中托管ASP.net核心Web应用程序。我能够创建一个自包含的部署并创建Windows服务。我的Web应用程序配置为http的端口为5000,https的端口为5001。在应用程序中,我使用HttpsRedirectMiddleware。

启动Windows服务时,只能通过http浏览网页,并从Https重定向中间件引发以下错误。

  

Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware失败   确定要重定向的https端口。

是否需要任何其他配置来公开用于https通信的端口?

Github Code Sample

2 个答案:

答案 0 :(得分:0)

See the documentation,了解用于配置非默认HTTPS端口的各种方式。

哪种方法最适合您的情况取决于您的应用程序的设置和托管方式。例如,您可以添加设置:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseSetting("https_port", "5001")
        .UseStartup<Startup>();

答案 1 :(得分:0)

我在调试模式下收到此警告。您只需要“启用SSL”,警告就会消失。

enter image description here

或者,如果您使用IIS,则可以编辑“高级设置”以启用https。 enter image description here