ASP.NET获取客户端IP地址

public static string GetRealIP()
        {
            string ip;
            try
            {
                HttpRequest request = HttpContext.Current.Request;

if (request.ServerVariables["HTTP_VIA"] != null)
                {
                    ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
                }
                else
                {
                    ip = request.UserHostAddress;
                }
            }
            catch (Exception e)
            {
                throw e;
            }

return ip;
        }

上一篇:hibernate使用注解设置日期默认值


下一篇:主成分分析(PCA)原理及R语言实现 | dimension reduction降维