首页  编辑  

获取客户端的信息

Tags: /C#/Web网络编成/   Date Created:

#region

#region

public static string getUserIp()

{

    return HttpContext . Current . Request . UserHostAddress;

}

/// <summary>

///

/// </summary>

/// <param name="page"> </param>

/// <returns> </returns>

public static string GetClientIP(System . Web . UI . Page page)

{

    string ipAddress = "" ;

    if (HttpContext . Current . Request . ServerVariables[ "HTTP_X_FORWARDED_FOR" ] == null )

   {

       ipAddress = HttpContext . Current . Request . ServerVariables[ "Remote_Addr" ];

   }

    else

   {

       ipAddress = HttpContext . Current . Request . ServerVariables[ "HTTP_X_FORWARDED_FOR" ];

   }

    return ipAddress;

}

#endregion

#region

public static string getUserHostName()

{

    return HttpContext . Current . Server . MachineName . ToString();

}

#endregion

#endregion