3
这是我Program.cs
:的.Net核心API起始URL
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://localhost:9020")
.UseIISIntegration()
.UseStartup<Startup>()
//.UseApplicationInsights()
.Build();
host.Run();
}
它用来在端口运行9020
作为UseUrls()
下指定。出于某种原因,现在当我启动该程序时,它会担任端口54033
和唯一的事情(我觉得)我已经改变是增加:
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
我.csproj
发布,但我没有看到这将如何影响运行服务的端口。有其他地方我可以检查这个问题吗?
这工作......但现在我不知道为什么不是'Program.cs'选项覆盖它?在两个地方改变它有什么意义? – Norgul
我不建议在代码中使用硬编码的网址,通过设置来设置它更简洁。 Program.cs中的代码被覆盖的原因是因为您是从Visual Studio启动应用程序,并将其配置存储在launchSettings.json文件中。 –