转自:http://www.cnblogs.com/yanbigfeg/p/9198345.html

介绍:

Asp.Net Core在Windows上可以采用两种运行方式。一种是自托管运行,另一种是发布到IIS托管运行。

自托管

首先有一个完好的.Net Core WebAPI测试项目,然后进入根目录运行   dotnet publish  ,来进行编译:

asp.net core WebAPI发布

 

然后在进入dll目录,也就是程序集目录:运行当前项目的主程序dll: dotnet  xxx.dll

asp.net core WebAPI发布

出现上面情况就是完成了,发布在了5000端口;

验证看一下:

asp.net core WebAPI发布

 修改默认端口:

.NET Core WebAP默认的端口号是5000,但是我们可以通过配置来修改端口号。

第一步:创建hosting.json文件:

{
  "server.urls": "http://*:8001;http://*:8002;http://*:8003"
}

第二部读取,并注册:

asp.net core WebAPI发布
     public static void Main(string[] args)
        {
            //BuildWebHost(args).Run();
            var config = new ConfigurationBuilder()
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("hosting.json", optional: true)
               .Build();

            var host = new WebHostBuilder()
                .UseKestrel()
                .UseConfiguration(config)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseApplicationInsights()
                .Build();

            host.Run();
        }
asp.net core WebAPI发布

相关文章:

  • 2022-12-23
  • 2021-10-16
  • 2021-06-10
  • 2021-05-15
  • 2022-01-26
  • 2021-06-13
猜你喜欢
  • 2021-11-13
  • 2022-12-23
  • 2021-10-07
  • 2022-02-21
  • 2022-01-19
  • 2022-02-25
相关资源
相似解决方案