标签:class blog http com get string
public static class Comm
{
/// <summary> /// 获得IP地址 /// </summary> /// <param name="request"></param> /// <returns></returns> public static string GetIPstring(HttpRequest request) { // 穿过代理服务器取远程用户真实IP地址 string Ip = string.Empty; if (request.ServerVariables["HTTP_VIA"] != null) { if (request.ServerVariables["HTTP_X_FORWARDED_FOR"] == null) { if (request.ServerVariables["HTTP_CLIENT_IP"] != null) Ip = request.ServerVariables["HTTP_CLIENT_IP"]; else if (request.ServerVariables["REMOTE_ADDR"] != null) Ip = request.ServerVariables["REMOTE_ADDR"]; else Ip = "0.0.0.1"; } else Ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } else if (request.ServerVariables["REMOTE_ADDR"] != null) { Ip = request.ServerVariables["REMOTE_ADDR"]; } else { Ip = "0.0.0.1"; } return Ip; }
}
在web页面中方法调用
string str_ip=Comm.GetIPstring(Request);
标签:class blog http com get string
原文地址:http://www.cnblogs.com/xinianxinqix/p/3806347.html