【发布时间】:2017-05-31 21:02:13
【问题描述】:
我正在使用 ASP.NET Core。我有两个项目:
- ASP.NET Core MVC 应用程序
- ASP.NET Core Web API 应用程序
如果我尝试使用 Postman 访问 Web API 端点之一,我没有任何问题; /api/values 端点按预期返回。 (这是标准测试端点。)
但是,如果我尝试使用 MVC 应用程序执行相同的操作,则会收到一个非常令人沮丧的错误:
HttpsConnectionFilter[1]
Failed to authenticate HTTPS connection
我正在使用 Kestrel for ASP.NET Core 进行托管。
我有一个使用 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");
如果我要运行这个,我会得到同样的错误:
var client = new HttpClient();
var content = await client.GetStringAsync("https://localhost:44301/api/values");
我的 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();
我知道我再次为上面的HttpClient 定义了证书,但我很绝望。
谁能提供一些关于为什么会发生这种情况以及我可以如何修复它甚至调试它的见解?我目前正在逐步检查KestrelHttpServer 代码,看看是否能提供一些见解。
这是我从 Kestrel 控制台窗口得到的完整错误:
信息:HttpsConnectionFilter1 无法验证 HTTPS 连接。 System.IO.IOException:身份验证失败,因为远程方已关闭 传输流。在 System.Net.Security.SslState.StartReadFrame(字节 [] 缓冲区,Int32 readBytes,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(IAsyncResult asyncResult) 在 System.Threading.Tasks.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, 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()
【问题讨论】:
标签: c# https asp.net-core asp.net-core-mvc kestrel-http-server