异常抛出:根据验证过程,远程证书无效。

17

你好,

我在我的一台PC(Windows 10)上使用Visual Studio 2019运行了一个ASP.NET CORE Blazor应用程序,它运行正常。但是当我在另一台PC(Windows 7)上使用VS Code打开同一个项目时,出现了以下异常。

{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}

内部异常为空,错误信息为:根据验证过程,远程证书无效。

我正在使用 .NET CORE SDK 3.1.0 预览版2。这是引发异常的代码:

@code{
    public List<ProjectVM> projectsDataSource { set; get; }

    public void ActionComplete(ActionEventArgs<Order> Args) { }

    protected override async Task OnInitializedAsync()
    {
        try
        {
            projectsDataSource = new List<ProjectVM>();
            projectsDataSource = await Http.GetJsonAsync<List<ProjectVM>>("/Api/Default/GetProjectsList");

        }
        catch(Exception e)
        {

        }
    }
}

请帮忙。
提前感谢。
2个回答

31
当您使用VS 2019运行代码时,它会在您的计算机上安装一个自签名证书以进行https重定向(将显示一个消息框提示证书安装情况)。但是,VS代码不会为您执行此操作。阅读此文档应该会有所帮助:https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-3.0&tabs=visual-studio#trust-the-aspnet-core-https-development-certificate-on-windows-and-macos 您可以尝试运行这些命令。
dotnet dev-certs https --clean
dotnet dev-certs https --trust

2
我已经执行了这些命令多次并重新启动了两次,但错误仍然存在。还有更多的指针吗? - Chris Bordeman
1
@ChrisBordeman 你尝试使用 dotnet run 命令启动你的项目了吗? - agua from mars
是的,效果相同。奇怪的是,Chrome和甚至iexplore都说证书在今天早些时候过期了,就在我开始遇到问题的时候。我已经去MMC中删除了个人和本地机器中的所有本地主机证书,并在两者的受信任根证书中进行了清除。然后我尝试再次清理/安装它们,这似乎是成功的,我甚至清除了浏览器缓存并重新启动了计算机。Chrome仍然显示证书无效且今天已过期!我还清除了SSL状态。无法想象它从哪里获取这些信息。 - Chris Bordeman
2
是的。我最终重新安装了VS和每个SDK/工具。然后是所有的Windows。下一个选项是切腹。 - Chris Bordeman
1
在切腹之前,尝试在 asp.net core 的 Github 存储库上提问。 - agua from mars
显示剩余4条评论

14
< p >来自agua from mars的答案没有考虑到,在您告诉操作系统信任之前,您还必须为开发生成本地证书。< /p > < p >您可以按照以下顺序运行命令,然后再次运行应用程序。< /p >
dotnet dev-certs https --clean
dotnet dev-certs https
dotnet dev-certs https --trust

命令dotnet dev-certs https生成证书。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接