直接上菜:
/// <summary>
/// 获取客户端IP地址
/// </summary>
/// <returns></returns>
public string GetClientIP()
{
try
{
string result = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == result || result == String.Empty)
{
result = System.Web.HttpContext.Current.Request.UserHostAddress;
}
return result;
}
catch (Exception e)
{
return "";
}
}
标签:Web,C#,ip,Request,System,Current,result,HttpContext,客户端 From: https://www.cnblogs.com/UsefulIdiot/p/17456971.html