It seems that IIS Express
does some works behinds the scense which include configuration of a SSL
certification. So, I concentrated on ASP.NET Core
's internal hosting component which is Kestrel
.
Firstly, I created and SSL certificate using PowerShell
by help of this command:
New-SelfSignedCertificate -DnsName localhost -CertStoreLocation "cert:\LocalMachine\My"
This command creats a certification which I can see it through management console / certificates
program. For more information see this. After creating a new certificate, you are required to export it as a pfx
file. To do so in the management console use follwing steps:
- Add
Certificates
snap-in to the management console.
- Navigate through
Personal\Certifcates
- Right click on your newly created certificate and, from "all tasks", select "export"
- Select the option which says: "Yes, export the private key"
- You'll see that the
pfx
is automatically selected. Click "Next"
- Set a password and saving location.
- You are done with creating a pfx file
Next step is to configure ASP.NET Core to use the pfx
file which is described here:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup < Startup > ()
.UseKestrel((hostingContext, options) =>
{
if (hostingContext.HostingEnvironment.IsDevelopment) {
options.Listen(IPAddress.Loopback, 9001);
options.Listen(IPAddress.Loopback, 9002, listenOptions => {
listenOptions.UseHttps("certificate.pfx", "password");
});
}
})
.Build();
Now, the problem should be resolved. If not, try the certificate which is created by the IIS Express
. This is also available in management console.