受欢迎的博客标签

How to specify multi port in ASP.NET Core 2.x ?

Published
1.ASP.NET Core 2.0 step 1: how to change default port 5000 public class Program { public static void Main(string[] args) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("hosting.json", optional: true) .AddCommandLine(args) .Build(); var host = WebHost.CreateDefaultBuilder(args) .UseKestrel(options => { options.AddServerHeader = false; // options.Listen(IPAddress.Loopback, 8000); }) .UseUrls("http://*:8000") .UseConfiguration(config) .CaptureStartupErrors(true) .UseSetting(WebHostDefaults.PreventHostingStartupKey, "true") .UseStartup() .Build(); host.Run(); } }how to run it cd x:\..\..\Nop.Webdotnet publish -c release cd X:\..\..\..\bin\Release\netcoreapp2.0\publishdotnet XX.web.dll step 2: Add AddCommandLine  public static void Main(string[] args) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("hosting.json", optional: true) .AddCommandLine(args) .Build(); var host = WebHost.CreateDefaultBuilder(args) .UseKestrel(options => { options.AddServerHeader = false; // options.Listen(IPAddress.Loopback, 8000); }) .UseUrls("http://*:8000") .UseConfiguration(config) .CaptureStartupErrors(true) .UseSetting(WebHostDefaults.PreventHostingStartupKey, "true") .UseStartup() .Build(); host.Run(); } }how to run itdotnet run --urls "http://*:7999"Other: Don't use options.Listen(IPAddress.Loopback, 9000) bind your port ,Otherwise, there will be the following error:Unable to start Kestrel. System.IO.IOException: Failed to bind to address http://localhost:9000, address already in use public static IWebHost BuildWebHost(string[] args) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("hosting.json", optional: true) .AddCommandLine(args) .Build(); return WebHost.CreateDefaultBuilder(args) .UseKestrel(options => { options.Listen(IPAddress.Loopback, 9000); }) .UseConfiguration(config) .UseStartup() .Build(); }change options.Listen(IPAddress.Loopback, 9000) to .UseUrls("http://*:6000")public static IWebHost BuildWebHost(string[] args) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("hosting.json", optional: true) .AddCommandLine(args) .Build(); return WebHost.CreateDefaultBuilder(args) .UseUrls("http://*:9000") .UseConfiguration(config) .UseStartup() .Build(); }2.ASP.NET Core 2.1 title iaspnetcore releasex:cd \cd x:\..\wwwiaspnetcoreNetcore20RTM\src\Presentation\Nop.Webdotnet publish -c release cd x:\..\wwwiaspnetcoreNetcore20RTM\src\Presentation\Nop.Web\bin\Release\netcoreapp2.1\publishdotnet Nop.Web.dll --urls "http://localhost:6000" title iaspnetcore debug port5999x:cd \cd x:\..\wwwiaspnetcoreNetcore20RTM\src\Presentation\Nop.Webdotnet run --urls "http://localhost:5999" .