ASPNETCORE_Kestrel__Certificates__Default__Path在.NETCore3.1中的行为
创始人
2024-09-20 09:30:29
0

在.NET Core 3.1中,ASPNETCORE_Kestrel__Certificates__Default__Path 属性的行为发生了变化。在之前的版本中,如果没有设置此属性,则 Kestrel 将使用当前目录中的 cert.pfx 文件作为默认证书。但是,在.NET Core 3.1中,如果未找到您指定的默认路径或默认证书,则 Kestrel 将不再使用当前目录中的 cert.pfx 文件作为默认证书。

为了解决这一问题,您可以使用以下代码将默认证书的路径设为当前目录中的 cert.pfx 文件:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel(options => {
            options.ConfigureHttpsDefaults(httpsOptions => {
                httpsOptions.ServerCertificateSelector = (context, name) => {
                    // use the cert.pfx file in the current directory
                    var certPath = Path.Combine(Directory.GetCurrentDirectory(), "cert.pfx");
                    return new X509Certificate2(certPath, "password");
                };
            });
        })
        .UseStartup()
        .Build();

    host.Run();
}

在此示例中,我们使用 options.ConfigureHttpsDefaults() 方法配置了 Kestrel 的 HTTPS 默认选项,并将证书选择委托指定为返回位于当前目录中的 cert.pfx 文件的 X509Certificate2 对象。

相比将路径硬编码在代码中,您也可以将路径作为应用程序配置的一部分,以便更轻松地进行更改:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel(options => {
            options.ConfigureHttpsDefaults(httpsOptions => {
                httpsOptions.ServerCertificateSelector = (context, name) => {
                    // use the cert.pfx file in the configured directory
                    var certPath = Path.Combine(Configuration["CertificateDirectory"], "cert.pfx");
                    return new X509Certificate2(certPath, "password");

相关内容

热门资讯

黑科技存在!(WPk)透视辅助... 1、黑科技存在!(WPk)透视辅助工具,(WPk)原生存在有挂,必胜教程(有挂透明)。2、WPk透视...
wepoke黑科技!aapok... wepoke黑科技!aapoker德州线上扑克,来玩app德州安卓有用吗,透明挂教程(原来真的有挂)...
德州ai神器下载!gg扑克平台... 德州ai神器下载!gg扑克平台发牌机制,推扑克辅助器,高科技教程(原本真的是有挂)1、很好的工具软件...
黑科技透明挂挂!(aapOKE... 黑科技透明挂挂!(aapOKER)透明挂辅助工具,(aapokER)最初是有挂,必胜教程(有挂软件)...
黑科技挂!(aApoker)透... 您好,AAPOKEr这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这...
智星德州菠萝有挂吗!德州aap... 智星德州菠萝有挂吗!德州aapoker俱乐部,aa扑克平台,玩家教程(往昔是真的有挂);智星德州菠萝...
wepoke黑科技功能演示!w... 您好,wepoke软件能玩吗这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多...
黑科技教程!(WpK)透视辅助... 黑科技教程!(WpK)透视辅助机制,(wpK)其实是真的有挂,科技教程(有挂技巧);最新版2024是...
黑科技科技!(wepoKe)软... 黑科技科技!(wepoKe)软件透明挂,(WEPOKE)素来是有挂,德州论坛(有挂教程);致您一封信...
wepoke算法!微扑克ai操... wepoke算法!微扑克ai操作,wpk游戏是否有挂,技巧教程(一向有挂);亲真的是有正版授权,小编...