获取客户端的数字格式(不是字符串格式)的最快方法是什么?
string format : 223.255.254.0
numeric format : 3758095872
我可以通过一些代码来计算这个
static public uint IPAddressToLong(string ipAddress)
{
var oIP = IPAddress.Parse(ipAddress);
var byteIP = oIP.GetAddressBytes();
var ip = (uint)byteIP[0] << 24;
ip += (uint)byteIP[1] << 16;
ip += (uint)byteIP[2] << 8;
ip += byteIP[3];
return ip;
}
基于 Request.UserHostAddress 字符串,但我希望 IIS 或 ASP.NET 预先计算它并且它隐藏在 HttpContext 中的某个地方。
我错了吗?