asp.net 获得客户端IP地址

来源:互联网 发布:unity3d wsd人物行走 编辑:程序博客网 时间:2024/06/06 00:59
public static string GetIP()        {            try            {                string uip = "";                if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)                {                    uip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();                }                else                {                    uip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();                }                if (uip == "")                {                    return "000.000.000.000";                }                else                {                    return uip;                }            }            catch            {                return "000.000.000.000";            }        }

原创粉丝点击