使用红隼在配置端口号? [英] Configurable port number when using Kestrel?
本文介绍了使用红隼在配置端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了以下,但它仍然无法正常工作。运行 DOTNET myapp.dll
仍显示它监听的http://本地主机:5000 一>
- 创建 hosting.json
代码:
{
server.url:HTTP:/ / *:5001
}
- 更新的Program.cs
代码:
公共类节目
{
公共静态无效的主要(字串[] args)
{
无功配置=新ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(hosting.json,可选:真的,reloadOnChange:真)
.Build();
VAR主机=新WebHostBuilder()
.UseConfiguration(配置)//添加
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
//.UseUrls(\"http://*:5001)
.UseIISIntegration()
.UseStartup<&启动GT;()
.Build();
host.Run();
}
}
- 更新 project.json
代码:
publishOptions:{
包含:
的wwwroot,
意见,
区/ ** /观点,
appsettings.json,
的web.config,
NLog.config,
hosting.json
]
解决方案
-
您需要变更单:
.SetBasePath
应该读取文件VAR配置之前调用=新ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(hosting.json,可选:真的,reloadOnChange:真)
.Build();
-
使用
server.urls
,没有server.url
I have done the following but it still doesn't work. Running dotnet myapp.dll
still shows it's listening http://localhost:5000.
- Create hosting.json
Code:
{
"server.url": "http://*:5001"
}
- Updated Program.cs
Code:
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();
}
}
- Updated project.json
Code:
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config",
"NLog.config",
"hosting.json"
]
解决方案
You need to change order:
.SetBasePath
should be called before file readingvar config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("hosting.json", optional: true, reloadOnChange: true) .Build();
Use
server.urls
, notserver.url
这篇关于使用红隼在配置端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文