- 準(zhǔn)備證書 (購(gòu)買 或 自己生成)
假設(shè)為 localhost.pfx,保存到某個(gè)目錄。
假設(shè)密碼為 password。
- 添加依賴引用(project.json)
"Microsoft.AspNet.Server.Kestrel.Https": ****
- 添加偵聽(tīng)端口(project.json)
"web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://*:8000;https://*:44300"
- 加載證書 (startup.cs)
// Configure
var sslCert = new X509Certificate2(Path.Combine(_environment.ApplicationBasePath, "Certs/localhost.pfx"), "password");
app.UseKestrelHttps( sslCert);
在asp.net core-rc1-final 中 Kestrel 服務(wù)器存在一個(gè)bug,就是reqeust.schema 不能正確返回值,當(dāng)為https時(shí)返回值是http。 所以還是等 asp.net core rc2的發(fā)布吧。