【发布时间】:2020-01-31 18:04:07
【问题描述】:
更新:
只有在使用 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
【问题讨论】:
-
应该是http还是https?
-
这可能只是隐藏了证书验证错误。
-
我已经用 cert 参数更新了问题。
-
你可以试试
Invoke-RestMethod https://localhost:5001/weatherforecast -CertificateThumbprint 7A16573FF2DBA47695B8CA15916D445C9361F255吗? -
@CodeRunner,
Invoke-RestMethod得到同样的错误。
标签: asp.net visual-studio powershell asp.net-core kestrel-http-server