Modify the default port of ASP. Net Core 2.0 and the default port of core
The default port of ASP. Net Core is 5000. If you want to run multiple instances on the same server, you cannot listen to port 5000. Each instance needs to listen to different ports. Of course, if you are using IIS or Jexus for hosting, you can run multiple instances without having to modify the port.
Method 1
The first method is to directly modify the program and specify the port when initializing the Kestrel Server:
Namespace ZKEACMS. webHost {public class Program {public static void Main (string [] args) {var host = new WebHostBuilder (). useKestrel (). useContentRoot (Directory. getCurrentDirectory ()). useIISIntegration (). useStartup (). useUrls ("http: // *: 5123") // specify the port directly. build (); host. run ();}}}
This method of writing directly to the program is obviously not recommended and inconvenient to use.
Method 2
You can modify the default port (5000) of. Net Core by setting the environment variable (ASPNETCORE_URLS ).
Development Environment
# Unix:ASPNETCORE_URLS="http://*:5123" dotnet run# Windows PowerShell:$env:ASPNETCORE_URLS="http://*:5123" ; dotnet run# Windows CMD (note: no quotes):SET ASPNETCORE_URLS=http://*:5123 && dotnet run
Visual Studio
Production Environment
# Unix:ASPNETCORE_URLS="http://*:5123" dotnet application.dll# Windows PowerShell:$env:ASPNETCORE_URLS="http://*:5123" ; dotnet application.dll# Windows CMD (note: no quotes):SET ASPNETCORE_URLS=http://*:5123 && dotnet application.dll
Linux Unit Configuration
Add an Environment configuration. Environment = ASPNETCORE_URLS = http: // *: 5123
[Unit]Description=ZKEACMS[Service]WorkingDirectory=/root/cmsExecStart=/usr/bin/dotnet /root/cms/ZKEACMS.WebHost.dllRestart=alwaysRestartSec=10SyslogIdentifier=zkeacmsUser=rootEnvironment=ASPNETCORE_ENVIRONMENT=ProductionEnvironment=ASPNETCORE_URLS=http://*:5123[Install]WantedBy=multi-user.target
Address: http://www.zkea.net/codesnippet/detail/post-83