asp.net core部署時自定義監聽端口,提高部署的靈活性


另一種方式 https://www.cnblogs.com/stulzq/p/9039836.html

 代碼截圖:

 

貼一下代碼,方便復制:

			//默認端口號5000
	        string port = "5000";

	        if (args.Length == 2)
	        {
		        if (args[0] == "-p")
		        {
			        string portStr = args[1];

					//判斷端口號是否正確 純數字驗證
			        if (Regex.IsMatch(portStr, @"^\d*$"))
			        {
				        port = portStr;
			        }
		        }
	        }

  使用方法:dotnet xxx.dll -p 端口號,例:dotnet helloworld.dll -p 8080,那么就會監聽8080端口


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM