Loading

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端口

posted @ 2017-08-11 09:43  晓晨Master  阅读(2297)  评论(1编辑  收藏  举报