获取服务器信息
例如:获取客户机IP地址:
public static string GetClientIP() { HttpRequest request = HttpContext.Current.Request; string ipAddress = ""; if (request.ServerVariables["HTTP_X_FORWARDED_FOR"] == null) { ipAddress = request.ServerVariables["Remote_Addr"]; } else { ipAddress = request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } if (ipAddress.IndexOf(",") > 0) { ipAddress = ipAddress.Substring(0, ipAddress.IndexOf(",")); } return ipAddress; }
其中,客户机服务器的有关信息都放在服务器变量中,有关变量参数,请参见 https://msdn.microsoft.com/zh-cn/library/ms524602.aspx