[英]How do I attach an SSL certificate to my asp dot net website without switching to IIS?
I have a certificate, say, "./mysite.pfx" (that I've received from letsenctrypt).我有一个证书,比如“./mysite.pfx”(我从letsenctrypt 收到的)。 To enable HTTPS, I replaced
为了启用 HTTPS,我替换了
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).但是现在,如果我访问该站点,它会以 MOZILLA_PKIX_ERROR_SELF_SIGNED_CERT 响应,这意味着它找不到证书文件(我猜这是因为 dotnet 发送了默认值)。 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?
文件路径在哪里写,如何配置asp dot net项目使用ssl证书和https协议? Windows 10, no IIS.
Windows 10,没有 IIS。
You can configure kestrel for your project in CreateHostBuilder method.您可以在 CreateHostBuilder 方法中为您的项目配置 kestrel。 Add SSL port listening (443 by default) and provide your certificate with password.
添加 SSL 端口侦听(默认为 443)并为您的证书提供密码。 Also do not forget to add redirection to https from http: Enforce HTTPS in ASP.NET Core
另外不要忘记从 http 添加重定向到 https: 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 ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.