asp.net core部署时自定义监听端口,提高部署的灵活性

时间:2023-03-09 17:45:53
asp.net core部署时自定义监听端口,提高部署的灵活性

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

代码截图:

asp.net core部署时自定义监听端口,提高部署的灵活性

贴一下代码,方便复制:

			//默认端口号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端口