前段时间做了个获取IP的例子,代码是百度上找的,因为是新手,写了几遍还是不太理解,在这里分享一下。
代码
#region
GetIp 获得IP地址
public static string GetIp()
{
if (System.Web.HttpContext.Current.Request.ServerVariables[ " HTTP_VIA " ] != null )
{
return System.Web.HttpContext.Current.Request.ServerVariables[ " HTTP_X_FORWARDED_FOR " ].
Split( new char [] { ' , ' })[ 0 ];
}
else
{
return System.Web.HttpContext.Current.Request.ServerVariables[ " REMOTE_ADDR " ];
}
}
#endregion
public static string GetIp()
{
if (System.Web.HttpContext.Current.Request.ServerVariables[ " HTTP_VIA " ] != null )
{
return System.Web.HttpContext.Current.Request.ServerVariables[ " HTTP_X_FORWARDED_FOR " ].
Split( new char [] { ' , ' })[ 0 ];
}
else
{
return System.Web.HttpContext.Current.Request.ServerVariables[ " REMOTE_ADDR " ];
}
}
#endregion

1376

被折叠的 条评论
为什么被折叠?



