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");
}