【问题标题】:Use https with Microsoft.AspNetCore.Server.WebListener将 https 与 Microsoft.AspNetCore.Server.WebListener 一起使用
【发布时间】:2016-09-14 13:51:14
【问题描述】:

我需要配置一个带有 WebListener 作为服务器和 https 协议的 Asp.net 核心 Web 应用程序。我找不到任何有关此的文档或常见问题解答。

我的 Progam.cs 是:

var host = new WebHostBuilder()
            .UseWebListener(options => {

             })                
            .UseContentRoot(Directory.GetCurrentDirectory())               
            .UseIISIntegration()
            .UseUrls("http://localhost:5001", "https://localhost:5002")                
            .UseStartup<Startup>()                
            .Build();

        host.Run();

如何在 https 中配置 WebListener?

提前谢谢大家!

【问题讨论】:

    标签: c# asp.net visual-studio asp.net-core


    【解决方案1】:

    一种方法是使用netsh 命令将您的 SSL 证书绑定到您的 WebListener 正在侦听的特定端口。有关如何执行此操作的更多信息,请参阅How to: Configure a Port with an SSL Certificate。证书绑定到端口后,您可以为您的 WebListener 指定一个 https url。您可以编写代码为您执行 netsh 部分(在您启动 WebListener 之前),但这可能超出了此问题的范围。

    在 Kestrel 中启用 https 要简单得多 - 您想使用 WebListener 的任何具体原因?使用 Kestrel 时,您可以执行以下操作(您还可以使用其他几个覆盖,例如使用商店中的证书):

    new WebHostBuilder().UseKestrel(options => options.UseHttps(@"C:\MyCert.pfx"));
    

    记得在你的 project.json 文件中包含 Microsoft.AspNetCore.Server.Kestrel.Https 包。

    我还在 StackOverflow 上找到了 this 问题,这可能有助于为您指明正确的方向。

    【讨论】:

    • 嗨,我不能使用 Krestel,因为我的客户端请求用户 WebListener。我已经用 Krestel 做了一个测试,它运行良好。
    • 明白。我们使用上面列出的方法(netsh 部分是用 C# 代码完成的),所以如果你不能让它工作,请告诉我。
    猜你喜欢
    • 2015-06-22
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多