Asp.net-Core
找不到 Kestrel 使用的自簽名可信證書
我有一個非常基本的自託管 .NET core 2.1 應用程序,具有以下配置:
public class Program { public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup<Startup>() .Build(); host.Run(); } }和非常典型的簡單控制器如下:
[Route("api/[controller]")] [ApiController] public class ValuesController : ControllerBase { // GET api/values [HttpGet] public ActionResult<IEnumerable<string>> Get() { return new string[] { "value1", "value2" }; } // GET api/values/5 [HttpGet("{id}")] public ActionResult<string> Get(int id) { return "value"; } // POST api/values [HttpPost] public void Post([FromBody] string value) { } // PUT api/values/5 [HttpPut("{id}")] public void Put(int id, [FromBody] string value) { } // DELETE api/values/5 [HttpDelete("{id}")] public void Delete(int id) { } }當我測試這個應用程序並導航到我的 HTTPS 本地端點埠(在我的例子中是 44325)時,這個應用程序工作得很好:
https://localhost:44325/api/values
到目前為止一切都很好。現在我想弄清楚這個 HTTPS 連接的證書來自哪裡,因為我沒有使用 IIS Express,而且確實證書不屬於 IIS Express:
當我搜尋其指紋時,我無法在我的證書儲存中找到上述證書。這個證書是如何生成的?我在哪裡可以找到它?為什麼此證書在 Edge 和 chrome 中有效,但在 Firefox 中不受信任?它是即時生成的嗎?
我的啟動設置如下:
{ "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:55894", "sslPort": 44325 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "Experimental1": { "commandName": "Project", "launchBrowser": true, "launchUrl": "api/values", "applicationUrl": "https://localhost:44325;http://localhost:55894", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }我使用的是 Experimental1 配置文件而不是 IIS Express,當我執行應用程序時,我看到了我的小控制台。
這個證書是如何生成的?
.NET Core SDK 在我們第一次執行時生成證書
dotnet new請參閱https://blogs.msdn.microsoft.com/webdev/2018/02/27/asp-net-core-2-1-https-improvements/
我在哪裡可以找到它?
SDK 將 ASP.NET Core HTTPS 開發證書安裝到本地使用者證書儲存中。
- 打開 MMC 中的證書管理單元。
- 證書 - 目前使用者
- 查找證書
- 搜尋
localhost為什麼此證書在 Edge 和 chrome 中有效,但在 Firefox 中不受信任?
的確。即使在執行之後
dotnet dev-certs https --trust,Firefox 也不信任該證書並抱怨說,“該證書不可信,因為它是自簽名的。 ”可能只是Firefox 不再信任自簽名證書。我的解決方法是添加一個安全例外。



