标签:令行 img host style art string 方法 start tin
Program.cs代码如下:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace myapi { public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseUrls("http://192.168.3.162:6600") .UseStartup<Startup>(); } }
命令行cmd进入发布目录输入命令:
dotnet myapi.dll
Program.cs代码如下:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace myapi { public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build()) .UseStartup<Startup>(); } }
命令行cmd进入发布目录输入命令:
dotnet myapi.dll --server.urls "http://192.168.3.185:7100"
Program.cs代码如下:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; namespace myapi { public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseConfiguration(new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("hosting.json", optional: true).Build()) .UseStartup<Startup>(); } }
项目添加"hosting.json "文件,代码如下:
{ "server.urls": "http://192.168.3.185:8800" }
命令行cmd进入发布目录输入命令:
dotnet myapi.dll
精心准备,转载请留下原文地址。
.Net Core实战教程(二):设置Kestrel的IP与端口的几种方法
标签:令行 img host style art string 方法 start tin
原文地址:https://www.cnblogs.com/weiweithe/p/10346855.html