pie*_*eru 10 c# https asp.net-core-mvc kestrel-http-server asp.net-core
我正在使用ASP.Net Core,我有2个项目.
如果我使用Postman尝试其中一个WebApi端点,我没有任何问题,并且/ api/values按预期返回(标准测试端点)
但是,如果我使用MVC应用程序尝试相同的操作,我会得到一个非常令人沮丧的错误:
HttpsConnectionFilter[1]
Failed to authenticate HTTPS connection
Run Code Online (Sandbox Code Playgroud)
我正在使用Kestrel托管Asp.Net核心.
我有一个使用PowerShell创建的自签名PFX证书,这是抛出异常的代码:
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");
Run Code Online (Sandbox Code Playgroud)
如果我要运行这个,我会得到同样的错误:
var client = new HttpClient();
var content = await client.GetStringAsync("https://localhost:44301/api/values");
Run Code Online (Sandbox Code Playgroud)
我的Kestrel设置在我的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();
Run Code Online (Sandbox Code Playgroud)
我知道我为上面的HttpClient再次定义了证书,但我很绝望.
任何人都可以提供一些见解,了解为什么会发生这种情况,以及如何修复它,甚至调试它,因为它让我发疯.我正在浏览并单步执行KestrelHttpServer代码,看看是否会提供一些见解.
这是我从Kestrel控制台窗口获得的完整错误
info:HttpsConnectionFilter 1 无法验证HTTPS连接.System.IO.IOException:身份验证失败,因为远程方已关闭传输流.在System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest)处于System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest)---从先前位置抛出异常的堆栈跟踪结束---位于System.Net.Security的System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult结果)的System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)中的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(). System.Threading.Tasks.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, Func2中的SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)endFunction,Action1 endAction, Task1 promise,Boolean requiresSynchronization)---抛出异常的前一个位置的堆栈跟踪结束---在System.Runtime.ExceptionServices.ExceptionDispatchInfo .Throw()在Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnec的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)tionFilter.d__6.MoveNext()
Aba*_*say 13
我为这个问题找到的最直接的解决方案是删除证书并添加信任标志。
dotnet dev-certs https --clean
dotnet dev-certs https --trust
Run Code Online (Sandbox Code Playgroud)
附注。我知道这已经过时了,但我只想把它留在这里给可能会遇到这个问题的人。
| 归档时间: |
|
| 查看次数: |
10552 次 |
| 最近记录: |