使用红隼在配置端口号? [英] Configurable port number when using Kestrel?

查看:261
本文介绍了使用红隼在配置端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了以下,但它仍然无法正常工作。运行 DOTNET myapp.dll 仍显示它监听的http://本地主机:5000




  1. 创建 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
    ]


    解决方案

    1. 您需要变更单: .SetBasePath 应该读取文件

        VAR配置之前调用=新ConfigurationBuilder()
      .SetBasePath(Directory.GetCurrentDirectory())
      .AddJsonFile(hosting.json,可选:真的,reloadOnChange:真)
      .Build();


    2. 使用 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.

    1. Create hosting.json

    Code:

    {
      "server.url": "http://*:5001"
    }
    

    1. 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();
        }
    }
    

    1. Updated project.json

    Code:

      "publishOptions": {
        "include": [
          "wwwroot",
          "Views",
          "Areas/**/Views",
          "appsettings.json",
          "web.config",
          "NLog.config",
          "hosting.json"
        ]
    

    解决方案

    1. 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();
      

    2. Use server.urls, not server.url

    这篇关于使用红隼在配置端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆