仅当使用Kestrel启动应用程序时,才会发生以下错误。
我已经为Microsoft.AspNetCore.Authentication.Negotiate
添加了以下两行
// in public void ConfigureServices(IServiceCollection services)
services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
// in public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseAuthentication();
我使用Visual Studio 2019创建了一个新的测试Asp.Net核心Web API项目(具有 Windows身份验证)。然后在Visual Studio中运行它,并弹出一个显示json返回的浏览器。
然后,我打开一个Powershell窗口并测试了URL。出现以下错误?
PS C:\> Invoke-WebRequest https://localhost:5001/weatherforecast
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-WebRequest https://localhost:5001/weatherforecast
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我找到了ASP.NET Core HTTPS development certificate
。
PS C:\> ls Cert:\CurrentUser\My | ? Subject -eq 'CN=localhost' | fl
Subject : CN=localhost
Issuer : CN=localhost
Thumbprint : 7A16573FF2DBA47695B8CA15916D445C9361F255
FriendlyName : ASP.NET Core HTTPS development certificate
NotBefore : 12/6/2019 4:45:04 PM
NotAfter : 12/5/2020 4:45:04 PM
Extensions : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid,
System.Security.Cryptography.Oid...}
它仍然出现错误?
PS C:\> Invoke-WebRequest https://localhost:5001/weatherforecast -CertificateThumbprint 7A16573FF2DBA47695B8CA15916D445C -UseDefaultCredentials
9361F255
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-WebRequest https://localhost:5001/weatherforecast -Certificate ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand