zoukankan      html  css  js  c++  java
  • .net core 修改网站启动端口

    https://blog.csdn.net/yenange/article/details/81675594

    第 1 种方式:写死在代码
    修改 Program.cs

    public static IWebHostBuilder CreateWebHostBuilder(string[] args)
    {
    var host =
    WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .UseKestrel(o => {
    o.Listen(IPAddress.Loopback, 6000);
    })
    ;
    return host;
    }
    第 2 种方式:写死在代码
    修改 Program.cs

    public static IWebHostBuilder CreateWebHostBuilder(string[] args)
    {
    var host =
    WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .UseUrls("http://localhost:5002;https://localhost:5003")
    ;
    return host;
    }
    第 3 种方式:配置json文件
    1. 增加 host.json 文件,内容:

    {
    "urls": "http://localhost:5004;https://localhost:5005"
    }
    2. 修改 Programe.cs 

    public static IWebHostBuilder CreateWebHostBuilder(string[] args)
    {
    var config = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("host.json", optional: true)
    .Build();

    var host = WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .UseConfiguration(config)
    ;

    return host;
    }
    第 4 种方式:命令行
     1. 修改 Program.cs

    public static IWebHostBuilder CreateWebHostBuilder(string[] args)
    {
    var config = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddCommandLine(args) //添加对命令参数的支持
    .Build();

    var host = WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    ;

    return host;
    }
    2. 运行 dotnet run 时加参数:

    dotnet run --urls="http://*:5005"
    ————————————————
    版权声明:本文为CSDN博主「吉普赛的歌」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/yenange/article/details/81675594

  • 相关阅读:
    autorun.inf删除方法
    Re_Write序列号
    最常用的正则表达式
    SQL聚合使用GROUP BY
    Ext.Net的Window控件的简单使用
    SQL统计查询一个表中的记录,然后减法运算
    C#金额转换为汉字大写
    Ext.Net的Button按钮的使用
    C# 参考之方法参数关键字:params、ref及out 引用
    C#连接ACCESS 2007数据库
  • 原文地址:https://www.cnblogs.com/kunlunmountain/p/11806300.html
Copyright © 2011-2022 走看看