using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;namespace test
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                string RefPage = "";
                if (Request.UrlReferrer != null)
                {
                    RefPage = Request.UrlReferrer.ToString();//获取来源页面
                }
                else
                {
                    RefPage = "";
                }
                HttpBrowserCapabilities browser =  Request.Browser;
                Guid strid = Guid.NewGuid();
                string strName =  strid.ToString("N");//随机产生用户名
                if (GetCookie("cookieName") == null)
                {
                    SetCookie("cookieName", strName, 7);
                }
                else
                {
                    strName =  GetCookie("cookieName");
                }                string strCurrent = Request.ServerVariables["HTTP_REFERER"];//获取访问页面
                if (strCurrent == null)
                {
                    strCurrent = HttpContext.Current.Request.Url.ToString();
                }
                else
                {
                    strCurrent = Request.ServerVariables["HTTP_REFERER"];//获取访问页面
                }
                string strBrowser =  browser.Browser;//获取浏览器名称
                string strOS = SystemCheck();//browser.Platform;
                string strVisiton = browser.Version;//获取浏览器版本
                string strIP = Request.UserHostAddress;//获取用户ip
                string strLang = Request.UserLanguages[0].ToString();//获取语言
                showdata(strName,strCurrent,strOS,strBrowser,strVisiton,strIP,strLang,RefPage);
        }
        #region 插入SQL语句
        public void showdata(string strUserName,string strCurrent,string strOS,string strBrowser,string strVisit,string strIP,string strLang,string RefPage)
        {
            string strText = "insert into Allvisit values('"+strUserName+"','"+strCurrent+"','"+strOS+"','"+strBrowser+"','"+strVisit+"','"+strIP+"','"+strLang+"','"+RefPage+"','"+DateTime.Now+"')";
            SqlConnection conn = new SqlConnection("server=ec.100to.com,8899;database=BQStatistics;uid=BQS;pwd=bqs_2010@123;");
            //SqlConnection conn = new SqlConnection("server=.;database=Log;uid=sa;pwd=sa");
            conn.Open();
            SqlCommand comm = new SqlCommand(strText,conn);
            comm.ExecuteNonQuery();
            conn.Close();
        }
        #endregion
        /// <summary>
        /// 设置COOKIE值
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="cookieValue"></param>
        /// <param name="day"></param>
        public static void SetCookie(string cookieName, string cookieValue, int day)
        {
            HttpCookie cookie = new HttpCookie(cookieName);
            cookie.Expires = DateTime.Now.AddDays(day);
            cookie.Value = cookieValue;
            HttpContext.Current.Response.Cookies.Add(cookie);
        }        /// <summary>
        /// 读取COOKIE值
        /// </summary>
        /// <param name="cookieName"></param>
        /// <returns></returns>
        public static string GetCookie(string cookieName)
        {
            string str = "";            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];
            if (cookie != null)
                str = cookie.Value.ToString();
            else
                str = null;            return str;
        }
        public static string SystemCheck() 
 { 
 string Agent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];
 if (Agent.IndexOf("NT 4.0") > 0) 
 { 
 return "Windows NT "; 
 } 
 else if (Agent.IndexOf("NT 5.0") > 0) 
 { 
 return "Windows 2000"; 
 } 
 else if (Agent.IndexOf("NT 5.1") > 0) 
 { 
 return "Windows XP"; 
 } 
 else if (Agent.IndexOf("NT 5.2") > 0) 
 { 
 return "Windows 2003"; 
 } 
 else if (Agent.IndexOf("NT 6.0") > 0) 
 { 
 return "Windows Vista"; 
 } 
 else if (Agent.IndexOf("WindowsCE") > 0) 
 { 
 return "Windows CE"; 
 } 
 else if (Agent.IndexOf("NT") > 0) 

 return "Windows 7 "; 
 } 
 else if (Agent.IndexOf("9x") > 0) 
 { 
 return "Windows ME"; 
 } 
 else if (Agent.IndexOf("98") > 0) 
 { 
 return "Windows 98"; 
 } 
 else if (Agent.IndexOf("95") > 0) 
 { 
 return "Windows 95"; 
 } 
 else if (Agent.IndexOf("Win32") > 0) 
 { 
 return "Win32"; 
 } 
 else if (Agent.IndexOf("Linux") > 0) 
 { 
 return "Linux"; 
 } 
 else if (Agent.IndexOf("SunOS") > 0) 
 { 
 return "SunOS"; 
 } 
 else if (Agent.IndexOf("Mac") > 0) 
 { 
 return "Mac"; 
 } 
 else if (Agent.IndexOf("Linux") > 0) 
 { 
 return "Linux"; 
 } 
 else if (Agent.IndexOf("Windows") > 0) 
 { 
 return "Windows"; 
 } 
 return "未知类型"; 
 
 } 
      
    }
}为什么得出来的数据不正确?
用户打开这个页面的时候保存到Cookie(针对本电脑),再次打开时候判断是否是同一台电脑,和判断是否过了有效期(7天),没过则提取Cookie,否则从新生成一个用户名!