Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取请求数值的最快方法';ASP.NET中的IP地址_Asp.net_Client_Ip_Uint - Fatal编程技术网

获取请求数值的最快方法';ASP.NET中的IP地址

获取请求数值的最快方法';ASP.NET中的IP地址,asp.net,client,ip,uint,Asp.net,Client,Ip,Uint,获取客户端的数字格式(而不是字符串格式)的最快方法是什么 string format : 223.255.254.0 numeric format : 3758095872 我可以用如下代码对其进行后期计算 static public uint IPAddressToLong(string ipAddress) { var oIP = IPAddress.Parse(ipAddress); var byteIP = oIP.GetAddress

获取客户端的数字格式(而不是字符串格式)的最快方法是什么

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;
    }
静态公共uint IPAddressToLong(字符串ipAddress)
{
var oIP=IPAddress.Parse(IPAddress);
var byteIP=oIP.GetAddressBytes();

var ip=(uint)byteIP[0]HttpContext似乎并没有比您已经看到的更神奇:HttpRequest.UserHostAddress中的字符串值

一些背景信息:

HttpContext.Current.Request
类型为
System.Web.HttpRequest
,实例化时将
System.Web.HttpWorkerRequest
作为参数

HttpWorkerRequest
是一个抽象类,通过托管实现实例化,在IIS中,类似于
System.Web.hosting.IIS7WorkerRequest
,然后实现抽象方法
GetRemoteAddress()
HttpWorkerRequest
,由
HttpRequest.UserHostAddress
内部使用

IIS7HttpWorkerRequest
知道它需要读取的
REMOTE_ADDR
是IIS属性,并且在传递请求上下文时经过了更多的抽象层之后,它最终都以调用
mgdgetServerVariaBlow(IntPtr pHandler、string pszVarName、out IntPtr ppBuffer、out int pcchBufferSize)结束;
在webengine.dll中,它只需将一个长度为
pcchBufferSize
的字符串写入
ppBuffer
中,其中包含与从
HttpRequest.UserHostAddress
中获得的内容相同的内容


由于我怀疑HttpContext中是否有其他部分可以获取fed请求发送者相关信息,因此我假设您必须继续使用自己的转换魔法,因为我在评论中发布的链接中有很多想法。

您可能会在