Authentication failed because the remote party has closed the transport stream in localhost when using https

First of all, I use .net core 2.1 to develop a single page application(angular 5). Following the link
https://www.hanselman.com/blog/DevelopingLocallyWithASPNETCoreUnderHTTPSSSLAndSelfSignedCerts.aspx

I installed the cert for localhost to run the commands

dotnet dev-certs https

And

dotnet dev-certs https --trust

To run the application, I used two ways. The first way was in Visual Studio 2017 I clicked F5. I found the windows showing the message:

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) …..

The second way is I run the command dotnet run to start the application. Sometimes in chrome it shows

warning sockjs.js:2998 WebSocket connection to 'ws://localhost:4200/sockjs-node/173/ypgvodsj/websocket' failed: WebSocket is closed before the connection is established.

Before I use https, it was just fine. However after I installed the localhost cert.., it was bad.

Now even I removed the localhost cert and re-installed it, it is still happening.

So I think that the localhost cert might cause the issue.

My code in 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();
  }

UPDATE:

In my program.cs

public static void Main(string[] args)
{
     CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
     WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>();

In Configure method of 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");
    }

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Thanks for the comment by @Aaron,

It was "applicationUrl": "https://localhost:5001"

Using the following then it works.

   "applicationUrl": "http://localhost:5000;https://localhost:5001"


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x