如何获取客户端IP、WEB服务器IP

 

  1. 获取客户端IP

private string GetClientIP()

{

string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

if (null == result || result == String.Empty)

{

result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

}

 

if (null == result || result == String.Empty)

{

result = HttpContext.Current.Request.UserHostAddress;

}

return result;

}

  1. 获取Web服务器IP

private string GetServerIP()

{

return System.Web.HttpContext.Current.Request.ServerVariables["Local_Addr"];

}

上一篇:Weblogic的config.xml文件详解(原创)


下一篇:英特尔发布量子计算测试芯片,挑战IBM