【发布时间】:2018-12-18 09:54:53
【问题描述】:
我有一个非常基本的自托管 .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,我在运行应用程序时看到了我的小控制台。
【问题讨论】:
标签: asp.net-core https asp.net-core-2.0 asp.net-core-webapi kestrel-http-server