Reputation: 4324
I am working on a fabric application where I have configured HTTPS. It is throwing an exception though I have a valid installed certificate.
Upvotes: 275
Views: 257159
Reputation: 15174
If you're using node, and your localhost certificate expired, your .key
and .pem
files will no longer be valid. So you need to remove & regenerate them. In you have "prestart": "node aspnetcore-https"
in your package.json
, this will automatically regenerate them for you, using the new (valid) localhost certificate (after running the dotnet dev-certs https --trust
command)
Upvotes: 1
Reputation: 23284
These instructions from this blog worked for me
Upvotes: 539
Reputation: 41
I had the same issue, but none of the answers here helped. I figured out that I was missing line in configuration which caused it. (I was running asp.net through docker compose) The missing line was:
ASPNETCORE_URLS=https://+:443;http://+:80
in docker-compose file:
version: '3.4'
services:
webapplication1:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+:443;http://+:80
ports:
- "80"
- "443"
volumes:
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro
Upvotes: 1
Reputation: 1354
I'm on a Mac (macOS 12.6.7) trying to run a ASP.NET Core website project in VS Code, and none of the above answers worked fully for me. Only almost.
How I made it work. Run the following commands in the terminal:
dotnet clean
dotnet dev-certs https --clean
dotnet dev-certs https --trust
Now I was able to run the project with dotnet run
and reloading the browser.
PS: If you're lazy, you can also chain the commands like this: dotnet clean && dotnet dev-certs https --clean && dotnet dev-certs https --trust
Upvotes: 7
Reputation: 12119
If you are visiting this page and if you are unfortunate like me who tried every single solution/approach mentioned on this page but nothing worked, then you may like to know what I did and solved my problem.
I was getting this error from my ASP.NET Core web application no matter how many times I deleted the localhost certificates.
Then, I created a self-signed certificate using Powershell with this command. [I copied this PowerShell snippet from somewhere on the internet. Cannot remember the source.] First, make sure that you have a writable location on your computer at C:\temp\. (You can use any other path as long as it can be read by your web app)
$cert = New-SelfSignedCertificate -DnsName mydemowebapp.net -CertStoreLocation cert:\LocalMachine\My
$pwd = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath C:\temp\cert.pfx -Password $pwd
Then, in my appsertings.Development.json, I added this entry.
"Kestrel": {
"EndPoints": {
"Https": {
"Url": "https://localhost:5000",
"Certificate": {
"Path": "C:\\temp\\cert.pfx",
"Password": "MyPassword",
"AllowInvalid": "true"
}
}
}
}
Ran the application, boom! problem solved. I used the same URL https://localhost:5000 as I found in my LaunceSettings.
I hate a solution like this, but at least I could continue my development with such a solution. I do not know what really happened recently that I had to face this issue. Was that a windows update? or something else? I don't know. I did not face this issue before, until recently. And yes, I remembered to run the Website in Kestrel rather than IIS.
Upvotes: 10
Reputation: 1
When I tried everything, I still got ERR_SSL_VERSION_OR_CIPHER_MISMATCH
.
You can try to delete bin
and obj
directories of all projects, then run dotnet restore
.
Working for me.
Upvotes: 0
Reputation: 1
If you wanted to get rid of this issue,then in launchsettings.json change "useSSL": false
Upvotes: -1
Reputation: 3196
Generate a new certificate:
$ dotnet dev-certs https --trust
The HTTPS developer certificate was generated successfully.
Upvotes: 3
Reputation: 1229
(for Windows, not sure if there's an equivalent issue/solution for other OSs)
In a command prompt or Powershell terminal:
certmgr.msc
and delete all localhost certificates under both Personal\Certificates and Trusted Root Certification Authorities\Certificates.dotnet dev-certs https -t
a single time to create and trust a new development certificate.dotnet dev-certs https --check --verbose
, or just try debugging your ASP.NET app again.You may also need to run dotnet dev-certs https --clean
before creating the new certificate.
Upvotes: 94
Reputation: 81
Open RUN , then type mmc.exe, then
double click certificate
Delete localhost cert in both folders
then open your powershell
dotnet dev-certs https --clean
dotnet dev-certs https
dotnet dev-certs https --trust
Upvotes: 5
Reputation: 101
For me deleting the files under file:\\%APPDATA%\Microsoft\SystemCertificates\My\Certificates
and run in cmd dotnet dev-certs https -t
solved my issue.
Upvotes: 10
Reputation: 1226
If dotnet dev-certs https --clean
not working.
Upvotes: 2
Reputation: 1023
One more detail - If you generally log in as a normal (non-admin) user, do NOT run the "dotnet dev-certs https" commands from an admin command prompt if you have a separate admin-level identity. Run them in a normal command prompt under your normal login. Ask me how I know. :-P
If you run these commands from an elevated command prompt (using a distinctly separate admin identity) you will experience the following:
If you see these issues, run the "dotnet dev-certs https" commands from a normal command prompt. Fixed it for me. Hope this helps someone without spending the time that I did on this!
Upvotes: 1
Reputation: 195
I ran into this problem and my solution was to restart. When I did and then reopened Visual Studio 2019, it asked me to accept a new SSL certificate. After that, I was able to run my program.
Upvotes: 1
Reputation: 15
I commented following line in 'Startup.cs' file, and it worked for me.
app.UseHttpsRedirection();
Upvotes: -2
Reputation: 937
In windows, dotnet dev-certs https --clean
doesn't work for me, I have to delete these localhost certs manually.
dotnet dev-certs https -t
Upvotes: 6
Reputation: 11
If you want to work with an environment that is not Development, don't forget that user secrets are only added automatically when env is Development.
You can use the AddUserSecrets methods to resolve this :
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureAppConfiguration((hostingContext, builder) =>
{
var env = hostingContext.HostingEnvironment;
if (env.IsEnvironment("Local"))
{
builder.AddUserSecrets<Startup>();
}
})
.UseStartup<Startup>();
});
Upvotes: 1
Reputation: 5835
I am on OSX and dotnet dev-certs https --clean
and sudo dotnet dev-certs https --clean
were not working for me. Finally I was able to fix it with the following steps.
localhost
certificatedotnet dev-certs https -t
You should now be able to run without the error.
Edit:
If, after following the above answer, you do run into an error that reads There was an error saving the HTTPS developer certificate...
check out this answer https://stackoverflow.com/a/56709117/621827
Upvotes: 78
Reputation: 2367
Not sure if this will help anybody else but I had exactly this issue on my Mac. I have the project in Dropbox and so it is shared across machines, on the '2nd' machine I had to go in and manually delete the 'obj' and 'bin' folders, then re-run the application and it all worked
Upvotes: 0
Reputation: 319
For me the problem was resolved by running:
Upvotes: 28
Reputation: 121
I had this issue on my Windows 10 system using visual studio. The problem seemed to be that the command used in the GUI to clear the local certs for HTTPS was failing with an error message that I can no longer reproduce.
The solution for me was to open the certmgr for the current windows account and to delete all of the personal localhost certs. There was ~20 certs there for me because I've tried re-creating them many times. After deleting all of those certs I ran my .Net core HTTPS API once more and everything worked!
In summary, open your certmgr for your current user and clear all personal/localhost certs.
Upvotes: 12
Reputation: 2325
I had a similar (but not exactly the same) problem.
With 2.1 you have to configure your certificate.
I do this now completely in appsettings.json.
You can find my posting here:
Configure self hosting Kestrel App with certificate for https (internet web server)
Only have a look to the solution...
Upvotes: 2