C# 引发异常:根据验证过程,远程证书无效

C# 引发异常:根据验证过程,远程证书无效,c#,asp.net,asp.net-core,httpclient,blazor,C#,Asp.net,Asp.net Core,Httpclient,Blazor,你好 我正在Visual Studio 2019上的一台PC(Windows 10)上运行ASP.NET CORE Blazor应用程序,它工作正常。我用VS代码在另一台PC(Windows7)上打开了同一个项目,并引发了以下异常 {System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.\r\n ---> System.Security.A

你好

我正在Visual Studio 2019上的一台PC(Windows 10)上运行ASP.NET CORE Blazor应用程序,它工作正常。我用VS代码在另一台PC(Windows7)上打开了同一个项目,并引发了以下异常

{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 according to the validation procedure.\r\n   at System.Net.Security.SslStream.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)\r\n   at System.Net.Security.SslStream.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslStream.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslStream.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslStream.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslStream.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslStream.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslStream.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)\r\n   at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Net.Security.SslStream.ThrowIfExceptional()\r\n   at System.Net.Security.SslStream.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)\r\n   at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)\r\n   at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)\r\n   at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__65_1(IAsyncResult iar)\r\n   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)\r\n   --- End of inner exception stack trace ---\r\n   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)\r\n   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\r\n   at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)\r\n   at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask)\r\n   at Microsoft.AspNetCore.Components.HttpClientJsonExtensions.GetJsonAsync[T](HttpClient httpClient, String requestUri)\r\n   at Workspace2.Pages.OrdersGrid.OnInitializedAsync() in c:\Users\dell\Desktop\Workspace2\Pages\OrdersGrid.razor:line 49}
请帮忙


提前感谢。

当您使用VS 2019运行代码时,它会在您的计算机上安装一个自签名证书,用于https重定向。(将显示一个消息框,通知证书安装)

但是VS代码并不适合你

阅读此文档应有助于:

您可以尝试运行此命令

dotnet开发人员证书https--clean
dotnet开发人员证书https--信任

来自火星的agua的回答没有考虑到您还必须生成本地开发证书,然后才能告诉您的操作系统信任它

您可以按此顺序运行命令,然后再次运行应用程序

dotnet dev-certs https --clean
dotnet dev-certs https
dotnet dev-certs https --trust

命令
dotnet dev certs https
生成证书。

我已经执行了几次这些命令并重新启动了两次,但是错误仍然发生。还有指针吗?@ChrisBordeman您是否尝试使用
dotnet run
命令启动项目?是的,效果相同。奇怪的是Chrome甚至iexplore都说证书今天早些时候过期了,就在我开始出现问题的时候。我已转到MMC删除个人计算机和本地计算机中的所有本地主机证书,以及两者的受信任根证书。然后我尝试再次清理/安装它们,这似乎是成功的,我甚至清除浏览器缓存并重新启动。Chrome仍然说证书无效,今天过期了!我还清除了SSL名单。无法想象这是从哪里来的。@ChrisBordeman看起来很傻,但你的约会是最新的吗?是的。我最终重新安装了VS和所有SDK/工具。然后是所有的窗户。下一个选择是hara kiri。
dotnet dev-certs https --clean
dotnet dev-certs https
dotnet dev-certs https --trust