訪問日志寫入類文件和執行頁面文件

頁面執行

///获取用户浏览器信息
            HttpBrowserCapabilities browser = Request.Browser;
            ///判断用户是否已经访问
            if (Session["Tdepot"] == null)
            {
                try
                {   ///定义对象
                  
                    ///执行数据库操作
                    ///
                
                    visitor.AddVisitor(Request.UserHostAddress, browser.Platform, browser.Browser,
                    browser.Version, Request.UserLanguages[0].ToString(), browser.Cookies, "AERO首頁");
                    ///添加已经访问的标志
                    Session["Tdepot"] = "Tdepot";
                }
                catch (Exception ex)
                {   ///跳转到异常错误处理页面
                    Response.Redirect("404.htm");
                }
            } 

類文件

public int AddVisitor(string sIP,string sOS,string sBrowser,string sVision,string sLanguage,bool bIsCookie,string from)
 {
  ///创建链接
  SqlConnection myConnection = new SqlConnection(
            ConfigurationManager.ConnectionStrings["EPS_WEBConnectionString"].ConnectionString);

  ///定义SQL语句
  string cmdText = "INSERT INTO webcount(IP,OS,Browser,Vision,Language,IsCookie,[from])VALUES("
   + "'" + sIP + "',"
   + "'" + sOS + "',"
   + "'" + sBrowser + "',"
   + "'" + sVision + "',"
   + "'" + sLanguage + "',"
   + "'" + (bIsCookie == true ? 1 : 0).ToString() + "',"
            + "'" + from  +"' ) ";
     
      
          
  ///创建Command
  SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
     //   DataSet ds = Cds("select top 1 * from server_IP order by create_date desc");

  ///定义返回值
  int nResult = -1;
        if (sIP.Substring(0, 3) != "192" && sIP.Substring(0, 3) != "127") //&& sIP != ds.Tables[0].Rows[0]["server_ip"].ToString ())
  try
  {
   ///打开链接
   myConnection.Open();
   ///执行SQL语句
   nResult = myCommand.ExecuteNonQuery();
  }
  catch(SqlException ex)
  {
   ///抛出异常
   throw new Exception(ex.Message,ex);
  }
  finally
  {   ///关闭链接
   myConnection.Close();
  }
  ///返回nResult
  return nResult;
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值