#命令行下支持https证书
netcore发布到iis里的话,更新程序挺不方便,考虑用命令行kestrel,用CTRL+C很容易就关了。
##首先申请证书、密码
##然后修改appsettings.json文件
加入:
"Kestrel": {
"Endpoints": {
"Https": {
"Url": "https://*:8443",
"Certificate": {
"Path": "mydomain.cn.pfx",
"Password": "1234465830392798"
}
}
}
}
** 上面的url端口号可以自己指定 **
** 证书文件名path、密码password **
##启动测试:
dotnet test.dll
# 网上搜到的其他一些说明,试了效果不如上面方便
ssl证书cmd加载 运行netcore程序
在.NET Core中,如果你需要通过命令行(CLI)运行一个使用SSL证书的应用程序,你可以使用dotnet命令并指定证书文件路径。这通常是通过环境变量或者直接在命令行中设置的参数来实现的。
假设你的.NET Core应用程序名为MyApp.dll,SSL证书文件为mycert.pfx,并且你知道它的密码。你可以使用以下命令来运行你的应用程序:dotnet MyApp.dll --server.ssl.certificate="mycert.pfx" --server.ssl.certificate-password="your_password"
确保你的应用程序项目文件(.csproj)包含了对应的SSL证书作为内容文件:
<ItemGroup>
<Content Include="path_to_your_pfx_file/mycert.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
用 LettuceEncrypt 自动拉取证书:
https://blog.csdn.net/zls365365/article/details/127343273
1:配置 HTTPS 证书参数.// appsettings.json
{
"LettuceEncrypt": {
"DomainNames": [ "example.com", "www.example.com" ],
"EmailAddress": "it-admin@example.com"
}
}
2:注册服务:
using Microsoft.Extensions.DependencyInjection;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddLettuceEncrypt();
}
}
就是这么简单,在 .NET Core 程序启动后,会自动请求,生成,绑定 Https 证书,不需要额外的一些配置,是非常方便的。