<tfoot id='hH4kF'></tfoot>
      <legend id='hH4kF'><style id='hH4kF'><dir id='hH4kF'><q id='hH4kF'></q></dir></style></legend>
      • <bdo id='hH4kF'></bdo><ul id='hH4kF'></ul>

      <i id='hH4kF'><tr id='hH4kF'><dt id='hH4kF'><q id='hH4kF'><span id='hH4kF'><b id='hH4kF'><form id='hH4kF'><ins id='hH4kF'></ins><ul id='hH4kF'></ul><sub id='hH4kF'></sub></form><legend id='hH4kF'></legend><bdo id='hH4kF'><pre id='hH4kF'><center id='hH4kF'></center></pre></bdo></b><th id='hH4kF'></th></span></q></dt></tr></i><div id='hH4kF'><tfoot id='hH4kF'></tfoot><dl id='hH4kF'><fieldset id='hH4kF'></fieldset></dl></div>
      1. <small id='hH4kF'></small><noframes id='hH4kF'>

      2. 尝试从 WebAPI 获取时无法验证 HTTPS 连接

        Failed to Authenticate HTTPS connection when attempting GET from WebAPI(尝试从 WebAPI 获取时无法验证 HTTPS 连接)

              <tbody id='BRjaA'></tbody>
              <bdo id='BRjaA'></bdo><ul id='BRjaA'></ul>
              • <legend id='BRjaA'><style id='BRjaA'><dir id='BRjaA'><q id='BRjaA'></q></dir></style></legend>
                <i id='BRjaA'><tr id='BRjaA'><dt id='BRjaA'><q id='BRjaA'><span id='BRjaA'><b id='BRjaA'><form id='BRjaA'><ins id='BRjaA'></ins><ul id='BRjaA'></ul><sub id='BRjaA'></sub></form><legend id='BRjaA'></legend><bdo id='BRjaA'><pre id='BRjaA'><center id='BRjaA'></center></pre></bdo></b><th id='BRjaA'></th></span></q></dt></tr></i><div id='BRjaA'><tfoot id='BRjaA'></tfoot><dl id='BRjaA'><fieldset id='BRjaA'></fieldset></dl></div>

                <small id='BRjaA'></small><noframes id='BRjaA'>

              • <tfoot id='BRjaA'></tfoot>

                1. 本文介绍了尝试从 WebAPI 获取时无法验证 HTTPS 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 ASP.NET Core.我有两个项目:

                  I am using ASP.NET Core. I have two projects:

                  1. ASP.NET Core MVC 应用程序
                  2. ASP.NET Core Web API 应用程序

                  如果我尝试使用 Postman 访问 Web API 端点之一,我没有任何问题;/api/values 端点按预期返回.(这是标准测试端点.)

                  If I attempt to access one of the Web API endpoints using Postman, I do not have any issues; the /api/values endpoint returns as expected. (This is the standard test endpoint.)

                  但是,如果我尝试使用 MVC 应用程序执行相同的操作,则会收到一个非常令人沮丧的错误:

                  If I attempt the same operation using the MVC application, however, I get a very frustrating error:

                  HttpsConnectionFilter[1]
                  Failed to authenticate HTTPS connection
                  

                  我正在使用 Kestrel for ASP.NET Core 进行托管.

                  I am hosting using Kestrel for ASP.NET Core.

                  我有一个使用 PowerShell 创建的自签名 PFX 证书,这是引发异常的代码:

                  I have a self-signed PFX certificate I created using PowerShell, and this is the code throwing the exception:

                  var handler = new HttpClientHandler();
                  handler.ClientCertificateOptions = ClientCertificateOption.Manual;
                  handler.SslProtocols = SslProtocols.Tls12;
                  handler.ClientCertificates.Add(new X509Certificate2("localcert.pfx", "xxx"));
                  var client = new HttpClient(handler);
                  
                  var content = await client.GetStringAsync("https://localhost:44301/api/values");
                  

                  如果我要运行这个,我会得到同样的错误:

                  And I get the same error if I were to run this:

                  var client = new HttpClient();
                  var content = await client.GetStringAsync("https://localhost:44301/api/values");
                  

                  我的 Kestrel 设置在我的 Program.cs 中是这样的:

                  My Kestrel setup is like so in my Program.cs:

                  var cert = new X509Certificate2("localcert.pfx", "xxx");
                  
                  var host = new WebHostBuilder()
                    .UseKestrel(cfg => cfg.UseHttps(cert))
                    .UseUrls("https://localhost:44300")
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseIISIntegration()
                    .UseStartup<Startup>()
                    .Build();
                  
                  host.Run();
                  

                  我知道我为上面的 HttpClient 再次定义了证书,但我很绝望.

                  I know I defined the certificate again for the HttpClient above, but I am desperate.

                  谁能提供一些关于为什么会发生这种情况以及我可以如何修复它甚至调试它的见解?我目前正在逐步执行 KestrelHttpServer 代码,看看是否能提供一些见解.

                  Can anyone offer some insight as to why this is happening and how I can go about fixing it, or even debugging it? I am currently in the process of stepping through the KestrelHttpServer code to see if that will offer some insight.

                  这是我从 Kestrel 控制台窗口得到的完整错误:

                  This is the full error I get from the Kestrel console window:

                  信息:HttpsConnectionFilter1无法验证 HTTPS 连接.System.IO.IOException:身份验证失败,因为远程方已关闭传输流.在System.Net.Security.SslState.StartReadFrame(字节 [] 缓冲区,Int32readBytes,AsyncProtocolRequest asyncRequest)在System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest异步请求)--- 从先前抛出异常的位置结束堆栈跟踪 --- 在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult懒惰的结果)在System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult结果)在System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResultasyncResult) 在System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResultiar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean需要同步)--- 从先前抛出异常的位置结束堆栈跟踪 --- 在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter.d__6.MoveNext()

                  info: HttpsConnectionFilter1 Failed to authenticate HTTPS connection. System.IO.IOException: Authentication failed because the remote party has closed the transport stream. at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) at System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter.d__6.MoveNext()

                  推荐答案

                  我为这个问题找到的最直接的解决方案是删除证书并添加信任标志.

                  The most straight forward solution I found for this problem was to remove the cert and add it with the trust flag.

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

                  PS.我知道这已经过时了,但我只是将其留给可能会遇到此问题的人.

                  PS. I know this is old but I am just going to leave this here for someone that might stumble to this issue.

                  这篇关于尝试从 WebAPI 获取时无法验证 HTTPS 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)

                    <bdo id='bHM27'></bdo><ul id='bHM27'></ul>
                      <tbody id='bHM27'></tbody>
                    <i id='bHM27'><tr id='bHM27'><dt id='bHM27'><q id='bHM27'><span id='bHM27'><b id='bHM27'><form id='bHM27'><ins id='bHM27'></ins><ul id='bHM27'></ul><sub id='bHM27'></sub></form><legend id='bHM27'></legend><bdo id='bHM27'><pre id='bHM27'><center id='bHM27'></center></pre></bdo></b><th id='bHM27'></th></span></q></dt></tr></i><div id='bHM27'><tfoot id='bHM27'></tfoot><dl id='bHM27'><fieldset id='bHM27'></fieldset></dl></div>

                        1. <small id='bHM27'></small><noframes id='bHM27'>

                        2. <tfoot id='bHM27'></tfoot>

                            <legend id='bHM27'><style id='bHM27'><dir id='bHM27'><q id='bHM27'></q></dir></style></legend>