asp.net core部署时自定义监听端口,提高部署的灵活性
原文连接:http://www.manongjc.com/detail/51-deiojnabsarikgh.html
用的是命令参数的方式,简单写的,代码很low,不喜勿喷!
代码截图:
贴一下代码,方便复制:
//默认端口号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端口