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");

相关内容

热门资讯

黑科技辅助挂!红龙扑克是不是有... 黑科技辅助挂!红龙扑克是不是有问题,wepoke辅助工具的使用教程,安装教程(有挂规律)-哔哩哔哩w...
黑科技ai代打!wpk有赢的吗... 您好,aapoker外挂实测这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多...
黑科技插件!德扑之星辅助器,w... 黑科技插件!德扑之星辅助器,wepoke到底有没有挂,介绍教程(有挂技巧)-哔哩哔哩1、构建自己的微...
黑科技ai辅助!aapoker... 黑科技ai辅助!aapoker辅助工具存在吗,德扑之星ai代打,技巧教程(有挂了解)-哔哩哔哩是一款...
黑科技ai辅助!wepoke一... 黑科技ai辅助!wepoke一定有挂,德扑之星辅助工具,规律教程(有挂教学)-哔哩哔哩是一款可以让一...
黑科技神器!wepoke软件透... 黑科技神器!wepoke软件透明挂价格,Wpk辅助器,技巧教程(有挂辅助挂)-哔哩哔哩1)wepok...
黑科技插件!Wepoke透明挂... 黑科技插件!Wepoke透明挂,wepoke有app软件吗,攻略教程(有挂规律)-哔哩哔哩;是一款可...
黑科技挂!wepoke是机器发... 黑科技挂!wepoke是机器发牌吗,微扑克辅助神器,2025新版教程(有挂黑科技)-哔哩哔哩;人气非...
黑科技ai!wepoke透明挂... 黑科技ai!wepoke透明挂怎么识别,wepoke黑科技设备,微扑克教程(有挂详情)-哔哩哔哩1、...
黑科技神器!智星菠萝德州辅助,... 黑科技神器!智星菠萝德州辅助,wepoke黑科技,实用技巧(有挂攻略)-哔哩哔哩(1)黑科技神器!智...