我正在使用ASP.Net Core,並且我有2個項目。嘗試從WebApi獲取GET時驗證HTTPS連接失敗
- ASP.Net MVC核心應用
- ASP.Net核心的WebAPI應用
如果我嘗試使用郵差我沒有任何問題的WebAPI終點之一和/ API /值收益預期(標準測試終點)
但是,如果我嘗試使用MVC應用程序,我得到一個非常令人沮喪的錯誤相同的操作:
HttpsConnectionFilter[1]
Failed to authenticate HTTPS connection
我正在使用Kestrel for 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");
,我也得到了同樣的錯誤,如果我是運行此:
var client = new HttpClient();
var content = await client.GetStringAsync("https://localhost:44301/api/values");
我的紅隼的設置是像這樣在我的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();
我知道我再定義的證書˚F或上面的HttpClient,但我絕望。
任何人都可以提供一些見解,爲什麼發生這種情況,我怎麼可以去解決它,甚至調試它,因爲它讓我發瘋。我正在通過KestrelHttpServer代碼來查看是否能提供一些見解。
這是完全錯誤我從紅隼控制檯窗口
info: HttpsConnectionFilter 1 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.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, Func
2 endFunction, Action1 endAction, Task
1 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()
我很高興你得到它的工作。我會在今晚嘗試,並希望分享你的成功:) – pieperu