/// <summary>
/// 获取客户端IP
/// </summary>
/// <returns></returns>
public static string GetClientIP()
{
string user_IP = string.Empty;
if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
user_IP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] { ',' })[0];
}
else
{
user_IP = HttpContext.Current.Request.UserHostAddress;
}
}
else
{
user_IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (user_IP == "::1") return "127.0.0.1";
return user_IP;
}
获取IP地址的方法
最新推荐文章于 2021-03-23 22:20:25 发布