使用 Kestrel 时可配置的端口号? [英] Configurable port number when using Kestrel?
本文介绍了使用 Kestrel 时可配置的端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已完成以下操作,但仍然无效.运行 dotnet myapp.dll
仍然显示它正在监听 http://localhost:5000.
I have done the following but it still doesn't work. Running dotnet myapp.dll
still shows it's listening http://localhost:5000.
- 创建hosting.json
代码:
{
"server.url": "http://*:5001"
}
- 更新了Program.cs
代码:
public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true, reloadOnChange: true)
.Build();
var host = new WebHostBuilder()
.UseConfiguration(config) // added
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
//.UseUrls("http://*:5001")
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
- 更新了project.json
代码:
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config",
"NLog.config",
"hosting.json"
]
推荐答案
你需要改变顺序:
.SetBasePath
应该在文件读取前调用
You need to change order:
.SetBasePath
should be called before file reading
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true, reloadOnChange: true)
.Build();
使用server.urls
,而不是server.url
这篇关于使用 Kestrel 时可配置的端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文