asp.net-core - 找不到 Kestrel 使用的自签名可信证书

标签 asp.net-core https asp.net-core-2.0 asp.net-core-webapi kestrel-http-server

我有一个非常基本的自托管 .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();
    }
}

非常典型的简单 Controller 如下:

   [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

enter image description here

到目前为止一切都很好。现在我想弄清楚此 HTTPS 连接的证书来自哪里,因为我没有使用 IIS Express 并且该证书实际上不属于 IIS Express: enter image description here

当我搜索其指纹时,我在证书存储中找不到上述证书。这个证书是如何生成的呢?我在哪里可以找到它?为什么此证书在 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,当我运行应用程序时,我看到了我的小控制台。

最佳答案

How does this certificate gets generated?

.NET Core SDK 在我们第一次运行 dotnet new 时生成证书

参见https://blogs.msdn.microsoft.com/webdev/2018/02/27/asp-net-core-2-1-https-improvements/

Where can I find it?

SDK 将 ASP.NET Core HTTPS 开发证书安装到本地用户证书存储中。

enter image description here

why does this certificate work in Edge and chrome but in Firefox its not trusted?

确实如此。即使在运行 dotnet dev-certs https --trust 后,Firefox 也不信任该证书,并提示“该证书不受信任,因为它是自签名的。

可能只是 Firefox no longer trusts self-signed certificates 。我的解决方法是添加安全异常(exception)。

enter image description here

关于asp.net-core - 找不到 Kestrel 使用的自签名可信证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51267154/

相关文章:

vue.js - 服务器端渲染 Vue 与 ASP.NET Core 2

c# - 如何使用 async Task<IActionResult> ?或者如何在我的 Asp.Net Core Web Api 中以异步方式运行

asp.net-core - 区分大小写的路由

http - 渐进式 Web 应用程序可以与本地网络上的设备一起使用吗?

authentication - Asp.Net Core 2 oidc中间件在代理请求返回401后不进行质询

c# - 如何使用 ef 为迁移构建强制执行 Restrict DeleteBehavior?

javascript - 通过 XMLHttpReques 发布数据不返回 json 值

c# - 在 .Net Core 中实现 IDbConnection

Docker 镜像未与 https 和 tomcat 一起运行

java - 骡子 ESB : Connect to https service