Kestrel在哪里寻找可以收听的端口



我有几个.NET Core应用程序,当我运行dotnet run时,它们决定侦听不同的端口(一个到5000,一个到同时到5000和5001(。

我一直在四处寻找一些关于这些决定是如何做出的全面文件,但找不到我想要的。

Kestrel在此设置中按优先顺序查找的位置列表是什么?

为了简单起见,假设我使用默认的WebHostBuilder:

public class Program
{
public static void Main(string[] args)
{
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build()
.Run();
}
}

根据Endpoint配置下的文档

默认情况下,ASP.NET Core绑定到:

  • http://localhost:5000
  • https://localhost:5001(当存在本地开发证书时(

源代码也支持此

/// <summary>
/// The endpoint Kestrel will bind to if nothing else is specified.
/// </summary>
public static readonly string DefaultServerAddress = "http://localhost:5000";
/// <summary>
/// The endpoint Kestrel will bind to if nothing else is specified and a default certificate is available.
/// </summary>
public static readonly string DefaultServerHttpsAddress = "https://localhost:5001";

内部AddressBinder使用它来设置在没有提供时默认使用的主机和端口。

最新更新