首先,我使用 .net core 2.1 开发单页应用程序(angular 5)。按照链接
https://www.hanselman.com/blog/DevelopingLocallyWithASPNETCoreUnderHTTPSSSLAndSelfSignedCerts.aspx
我为 localhost 安装了证书以运行命令
dotnet dev-certs https
和dotnet dev-certs https --trust
为了运行应用程序,我使用了两种方法。第一种方法是在 Visual Studio 2017 中单击 F5。我发现显示消息的窗口:dbug: HttpsConnectionAdapter[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[] butter, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) .....
第二种方法是我运行命令
dotnet run
启动应用程序。有时在 chrome 中它显示warning sockjs.js:2998 WebSocket connection to 'ws://localhost:4200/sockjs-node/173/ypgvodsj/websocket' failed: WebSocket is closed before the connection is established.
在我使用https之前,它很好。但是在我安装了 localhost cert..
之后, 这不怎么样。现在,即使我删除了 localhost 证书并重新安装它,它仍然在发生。
所以我认为 localhost 证书可能会导致问题。
我在 Startup.cs 中的代码
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc();
}
更新:在我的 program.cs
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
在 Startup.cs 的配置方法中app.UseSpa(s =>
{
s.Options.SourcePath = "ClientApp";
if(env.IsDevelopment())
{
s.Options.StartupTimeout = new System.TimeSpan(0, 0, 180);
s.UseAnagularCliServer(npmScript: "start");
}
最佳答案
感谢@Aaron 的评论,
它是 "applicationUrl": "https://localhost:5001"
使用以下内容即可。
"applicationUrl": "http://localhost:5000;https://localhost:5001"
关于c# - 身份验证失败,因为远程方在使用 https 时关闭了 localhost 中的传输流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63816088/