通过appsettings.json 配置HTTPS证书,这样配置比写在代码中更灵活。

在appsettings.json 添加如下代码块即可

"Kestrel": {
        "Endpoints": {
            "Https": {
                "Url": "https://*:443",
                "Certificate": {
                    "Path": "域名.com.pfx",
                    "Password": "证书的密码"
                }
            }
        }
    }

整体如下

{
    "Logging": {
        "LogLevel": {
            "Default": "Information",
            "Microsoft": "Warning",
            "Microsoft.Hosting.Lifetime": "Information"
        }
    },
    "AllowedHosts": "*",
    "Kestrel": {
        "Endpoints": {
            "Https": {
                "Url": "https://*:443",
                "Certificate": {
                    "Path": "域名.com.pfx",
                    "Password": "证书的密码"
                }
            }
        }
    }
}

更多推荐