Reputation: 130
I have a certificate, say, "./mysite.pfx" (that I've received from letsenctrypt). To enable HTTPS, I replaced
webBuilder.UseUrls("http://*:80");
with
webBuilder.UseUrls("http://*:80", "https://*:443");
But now if I visit the site it responds with MOZILLA_PKIX_ERROR_SELF_SIGNED_CERT meaning that it cannot find the certificate file (I guess that's because dotnet sends a default). Where do I write the path to the file, how do I configure asp dot net project to use the ssl certificate and https protocol? Windows 10, no IIS.
Upvotes: 0
Views: 1097
Reputation: 141
You can configure kestrel for your project in CreateHostBuilder method. Add SSL port listening (443 by default) and provide your certificate with password. Also do not forget to add redirection to https from http: Enforce HTTPS in ASP.NET Core
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseKestrel(options =>
{
options.Listen(IPAddress.Any, 80); // http
options.Listen(IPAddress.Any, 443, listenOptions => // https
{
listenOptions.UseHttps("certificate.pfx", "certificate-password");
});
});
webBuilder.UseStartup<Startup>();
// other stuff ...
}
Upvotes: 3