ASP.NET Core — Localhost Environment Certificate Not Trust Issue
Problem
2 min readJul 31, 2019
In ASP.NET Core, when we create a default App or API project, it will enable SSL and automatically redirect from HTTP to HTTPS.
Here are the settings how it works:
- In Startup.cs, it calls app.UseHttpsRedirection() for redirecting HTTP to HTTPS
- In launchSettings.json, it uses “https://localhost:5001;http://localhost:5000"
It is great to always to use SSL even on local development environment, but it has some certificate issue,
If you just access the URL via browsers, you may be able to skip this error. But when you call API via C# code, then you will have certificate issue.
Solution
dotnet core has a really great tool call dev-certs, which can solve this issue easily.
Check the help of dotnet dev-certs
dotnet dev-certs https --help
Trust the HTTPS development certificate
dotnet dev-certs https --trust
Then your problem will be solved!!