无法在Windows服务中使用带有Kestrel的* .pfx证书

问题描述 投票:0回答:1

我正在尝试使用Windows Service和Kestrel配置ASP.Net Core 3.1应用程序。到目前为止,该应用程序可以正常运行并启动。在控制台模式下也可以正常工作。

但是,当我在证书(* .pfx容器)中添加https时,情况会变得很奇怪。该应用程序可在没有问题的控制台中正常工作,但在服务模式下会失败,但例外:

System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, Func`2 createBinding)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

使用Microsoft.Extensions.Hosting.WindowsServices配置服务模式。一切都使用ConfigureWebHostDefaults()进行配置,而没有关于证书或其他任何细节的信息。这是来自appsettings.json的摘录:

"Urls": "https://*",
"Kestrel": {
    "Certificates": {
        "Default": {
            "Path": "full_path_to_my_certificate_container.pfx",
            "Password": "password"
        }
    }
}

在控制台模式下可以完美工作,正确应用证书,可以访问应用程序。使用服务模式无需任何配置更改。甚至环境都是相同的(实际上甚至没有设置,因此它是一种“生产”)。尝试将服务帐户切换到我的管理员帐户。完全没有区别。

我想念什么?

UPDATE_01:

我已将配置从“ * .pfx”证书更改为存储:

{
    "Kestrel": {
        "Certificates": {
            "Default": {
                "Location": "LocalMachine",
                "Store": "Root",
                "Subject": "MyCertSubjectName"
            }
        }
    }
}

和以前一样,它在控制台模式下可以完美运行,但在服务模式下不能提供相同的例外。

UPDATE_02:

尝试过此链接中的完整“端点”块:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#listenoptionsusehttps

完全没有区别。我可以看到我的配置已正确使用,因为使用不正确的值对其进行了测试,并且该应用在日志中报告了它们。

UPDATE_03:

在商店中使用我的证书的权限玩耍。没运气。

我迷路了...

asp.net-core https windows-services ssl-certificate
1个回答
0
投票

我感到as愧...似乎在服务模式下未读取我的配置。我只在控制台模式下测试了这个事实(这很容易),并认为它在服务模式下可以正常工作,因此这就是为什么我排除了这一部分的原因。

[将其移至appsettings.json时,一切正常。

对不起,如果有人正在为此主题输入评论...

© www.soinside.com 2019 - 2024. All rights reserved.