c# - 身份验证失败,因为远程方在使用 https 时关闭了 localhost 中的传输流

标签 c# asp.net angular ssl .net-core

首先,我使用 .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/

相关文章:

c# - 处理排队的命令处理程序响应。 CQRS

c# - 如何加入新指南列表?

asp.net - UpdatePanel 中的按钮需要单击两次才能触发

c# - 动态创建动态 RadioButtonsList

angular-cli - 如何更改生成的 css/js 包文件的名称

jquery - 如何关闭 Angular 4 Accordion 内的所有菜单

javascript - clearTimeout 偶尔失败

C# xml serializer - 序列化派生对象

c# - 基于内部属性展平集合

javascript - jQuery JSON 发布 : Invalid object passed in, ':' 或 '}' 预期