C# 在.NET控制台应用程序中为Kestral WebHost builder配置SSL证书
我正在控制台应用程序中创建一个ASP.NET WebAPI端点,我需要将其作为Windows服务宿主。 现在,除了端点在http中之外,其他一切都正常工作。我想使用https 当我通过VisualStudio运行它时。 我相信Kestral是IIS背后的反向代理,SSL证书是经过验证的。但当我把它作为Windows服务托管时。尝试到达终结点时,我收到证书错误 这是我的Kestral WebHost builderC# 在.NET控制台应用程序中为Kestral WebHost builder配置SSL证书,c#,.net,ssl,kestral,C#,.net,Ssl,Kestral,我正在控制台应用程序中创建一个ASP.NET WebAPI端点,我需要将其作为Windows服务宿主。 现在,除了端点在http中之外,其他一切都正常工作。我想使用https 当我通过VisualStudio运行它时。 我相信Kestral是IIS背后的反向代理,SSL证书是经过验证的。但当我把它作为Windows服务托管时。尝试到达终结点时,我收到证书错误 这是我的Kestral WebHost builder var configigurations = new Co
var configigurations = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false)
.Build();
var host = new WebHostBuilder()
.UseKestrel(options =>
{
options.ListenAnyIP(443, listenOptions =>
{
listenOptions.UseHttps("sslcertificate.pfx", "ssl@123");
});
})
.UseUrls(config.ApiBaseUrl)
.UseConfiguration(configigurations)
.UseStartup<Startup>()
.Build();
host.Run();
var configigurations=new ConfigurationBuilder()
.AddJsonFile(“appsettings.json”,可选:false)
.Build();
var host=new WebHostBuilder()
.UseKestrel(选项=>
{
options.listenyIP(443,listenOptions=>
{
UseHttps(“sslcertificate.pfx”ssl@123");
});
})
.useURL(config.ApiBaseUrl)
.UseConfiguration(配置配置)
.UseStartup()
.Build();
host.Run();
因为它作为Windows服务运行并公开API,所以我不能依赖IIS。我需要为Kestral进行配置
但是我怎么能呢
这将创建一个证书
dotnet dev-certs https -ep $env:USERPROFILE\.aspnet\https\aspnetapp.pfx -p crypticpassword
这将创建信任
dotnet dev-certs https --trust
好的,这是一个控制台应用程序。但是在它里面有一个API端点。对吗?当您在VisualStudio中运行它时,它会命中端点,当部署为Windows服务时,它会抛出证书验证错误。这是你的问题,对吗?没错。我正在尝试在本地系统上安装它
dotnet dev-certs https --trust