sunny123456

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

asp.net core部署时自定义监听端口,提高部署的灵活性
原文连接:http://www.manongjc.com/detail/51-deiojnabsarikgh.html

用的是命令参数的方式,简单写的,代码很low,不喜勿喷!

 代码截图:

![](https://img2023.cnblogs.com/blog/1192734/202301/1192734-20230107220830978-140238576.png)

贴一下代码,方便复制:


//默认端口号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 on 2023-01-07 22:03  sunny123456  阅读(116)  评论(0编辑  收藏  举报