在.Net 5下使用HTTPS调用gRPC服务时发生证书错误:不可信

在.Net 5下使用HTTPS调用gRPC服务时发生证书错误:不可信,https,grpc,.net-5,Https,Grpc,.net 5,我正在尝试用HTTPS连接我的gRPC客户端和服务,它们都在本地Windows 10计算机上的.Net 5下运行。现在我收到此证书错误,不确定如何修复: Status(StatusCode=\"Internal\", Detail=\"Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner excep

我正在尝试用HTTPS连接我的gRPC客户端和服务,它们都在本地Windows 10计算机上的.Net 5下运行。现在我收到此证书错误,不确定如何修复:

    Status(StatusCode=\"Internal\", Detail=\"Error starting gRPC call. 
    HttpRequestException: The SSL connection could not be established, see inner exception. 
    
    AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot\", DebugException=\"System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.\r\n 
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot\r\n   at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)\r\n   at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)\r\n   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)\r\n   --- End of inner exception stack trace ---\r\n   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.GetHttp2ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)\r\n   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)\r\n   at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)\")
我试图通过运行以下命令来安装开发人员证书,但似乎已经存在一个:

而且我似乎在我的个人和受信任的根存储下都有这个证书


但是,我注意到,我的商店中存在的证书是“IIS Express开发证书”,而不是“ASP.NET核心HTTPS开发证书”。那有关系吗?如果是,如何安装正确的证书?如果没有,我还缺少什么?

如果有人感兴趣-在我的情况下,这是因为在我当前的Windows构建级别下,IIS不支持gRPC托管。在我等待MS完成解决方案时,我只是在gRPC客户端添加了以下内容:

    var httpHandler = new HttpClientHandler();
    httpHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
    var channel = GrpcChannel.ForAddress(ServerAddress, new GrpcChannelOptions { HttpHandler = httpHandler });
正如您所看到的,这段代码是临时性的,不适用于生产。微软最近表示,该支持已包含在操作系统的build 20241或更高版本中,我计划在未来几周进行测试