怎么获取用户登录的IP地址???
我想记录用户操作IP地址
怎么获取??
一:this.Page.Request.UserHostAddress.ToString();
二: public static string GetIPAddress()
{
string user_IP = string.Empty;
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
user_IP = System.Web.HttpContext.Current.Request.UserHostAddress;
}
}
else
{
user_IP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
return user_IP;
}
还有什么方法,获取最真实的IP地址
[解决办法]
string ip = Request.ServerVariables["Remote_Addr"];
string ip = Request.UserHostAddress;
[解决办法]