日期:2014-05-17  浏览次数:20526 次

Asp.net网站如何保存用户的历史访问记录
如题将用户的ip地址,及ip所在的地址存入数据库,最好有代码

------解决方案--------------------
C# code


if (Request.ServerVariables["HTTP_VIA"] != null)
            {
                GuestIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else
            {
                if (Request.ServerVariables["HTTP_VIA"] != null)
                {
                    GuestIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                }
                else
                {
                    GuestIP = Request.ServerVariables["REMOTE_ADDR"].ToString();
                }

            }

------解决方案--------------------
C# code
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;
  }

------解决方案--------------------
探讨

C# code


if (Request.ServerVariables["HTTP_VIA"] != null)
{
GuestIP = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
……