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

相关内容

热门资讯

透视揭露!wepoker模拟器... 透视揭露!wepoker模拟器哪个,we-poker靠谱吗-竟然存在有辅助神器(哔哩哔哩)在进入软件...
透视辅助!hhpoker有没有... 透视辅助!hhpoker有没有作弊辅助,hhpoker是内部控制吗-总是是有辅助软件(哔哩哔哩)1、...
透视普及!aapoker透视插... 透视普及!aapoker透视插件,aapoker万能辅助器-好像一直总是有辅助神器(哔哩哔哩)一、可...
透视解谜!wpk控制牌是真的吗... 透视解谜!wpk控制牌是真的吗,微扑克微乐辅助-真是有辅助神器(哔哩哔哩)1、打开软件启动之后找到中...
透视解谜!wpk透视辅助方法,... 透视解谜!wpk透视辅助方法,wpk德州局透视-本来是有辅助脚本(哔哩哔哩)1、用户打开应用后不用登...
透视普及!wepokerh5破... 透视普及!wepokerh5破解,wepokerplus透视脚本免费-都是一直总是有辅助技巧(哔哩哔...
透视解谜!wepoker黑侠破... 透视解谜!wepoker黑侠破解,wepoker作弊视频-好像一直都是有辅助攻略(哔哩哔哩);1、打...
透视开挂!we-poker辅助... 透视开挂!we-poker辅助,wepoker有辅助器吗-都是存在有辅助脚本(哔哩哔哩)1、辅助软件...
透视详情!wepokerplu... 透视详情!wepokerplus透视脚本免费,wepoker辅助器是真的吗-好像一直总是有辅助方法(...
透视总结!wpk安卓下载辅助,... 透视总结!wpk安卓下载辅助,wpk辅助插件-原来存在有辅助插件(哔哩哔哩)一、游戏安装教程牌型概率...