<span style="font-family:SimHei;font-size:12px;"> /// <summary>
/// 获取客户端ip
/// </summary>
/// <returns></returns>
public static string GetIPAddress()
{
string user_IP = string.Empty;
if(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"]!= null)
{
if(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]!= null)
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
user_IP =System.Web.HttpContext.Current.Request.UserHostAddress;
}
}
else
{
user_IP =System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
return user_IP;
}</span>
C#获取客户端ip
最新推荐文章于 2024-05-06 08:00:33 发布