• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

基于事件日志的访问记录(c#)以后备用!

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
引用
 using System;
 using System.Data;
 using System.Web;
 using System.Web.UI;
 using function;
 namespace count
 {
 
 
   public class Vister:Page
   {
     SqlCmd ss=new SqlCmd();
     FileCmd ff=new FileCmd();
     EventLog even=new EventLog();
     Datetime t1=new Datetime();
     Root theroot=new Root();
 
     HttpContext context = HttpContext.Current;
     public string _referrer;
     public string _url=null;
     string evenlogpath="referrer.log";
     string mide=" ";
 
 
     public string referrer
     {
       get
       {
         return _referrer;
       }
       set
       {
         _referrer=value;
       }
     }
 
     public string url
     {
       get
       {
         return _url;
       }
       set
       {
         _url=value;
       }
     }
 
     public bool updateing
     {
       get
       {
         if (context.Application["updateing"]==null)
         {
           context.Application.Lock();
           context.Application["updateing"]=false;
           context.Application.UnLock();
         }
         return (bool)context.Application["updateing"];
       }
       set
       {
         context.Application.Lock();
         context.Application["updateing"]=value;
         context.Application.UnLock();
       }
     }
 
     public DateTime stday
     {
       get
       {
         if (context.Application["stday"]==null)
           context.Application["stday"]=DateTime.Now;
         return DateTime.Parse(context.Application["stday"].ToString());
 
       }
       set
       {
         context.Application["stday"]=value;
       }
     }
     public object todayvister
     {
       get
       {
         if (context.Application["todayvister"]==null || stday<DateTime.Now)
         {
           context.Application.Lock();
           stday=DateTime.Now;
           context.Application["todayvister"]=getrefcount(DateTime.Now);
           context.Application.UnLock();
         }
         return context.Application["todayvister"];
 
       }
       set
       {
         context.Application["todayvister"]=value;
 
       }
     }
     public object online
     {
       get
       {
         return "1";
       }
     }
     public object lastvister
     {
       get {
         if (context.Application["lastvister"]==null || stday<DateTime.Now)
         {
           context.Application.Lock();
           stday=DateTime.Now;
           context.Application["lastvister"]=getrefcount(DateTime.Now.AddDays(-1));
           context.Application.UnLock();
         }
 
         return context.Application["lastvister"];
       }
       set
       {
         context.Application["lastvister"]=value;
 
       }
     }
 
     public Vister()
     {
       //
       // TODO: 在此处添加构造函数逻辑
       //
       
     }
     public int getrefcount(DateTime time)//这里把它转换成一个DATATABLE,方便以后处理
     {
  return reftable(time).Rows.Count;
     }
     public DataTable reftable(DateTime time)
     {
       string str="";
       DataTable dt=new DataTable();
       str=ff.readfile(theroot.foderpath()+"log/"+t1.endate(time,"yyyy-MM-dd")+"."+evenlogpath);
       str=str.Replace("\r\n","$");
       string[] sArray=str.Split('$');
       DataRow dr;
       dt.Columns.Add(new DataColumn("DateTime",typeof(string)));
       dt.Columns.Add(new DataColumn("IP",typeof(string)));
       dt.Columns.Add(new DataColumn("Url",typeof(string)));
       dt.Columns.Add(new DataColumn("UrlReferrer",typeof(string)));
       dt.Columns.Add(new DataColumn("UserAgent",typeof(string)));
       for (int i=0;i<sArray.Length-1;i++)
       {
         string sa=sArray[i];
         sa=sa.Replace(mide,"#");
         string[] aa=sa.Split('#');
         dr = dt.NewRow();
         dr[0] = aa[0];
         dr[1] = aa[1];
         dr[2] = aa[2];
         dr[3] = aa[3];
         dr[4] = aa[4];  
         dt.Rows.Add(dr);
       }
       return dt;
 
     }
     public String browser(string str)
     {
       if (str.Split(';')[1]==" U")
         return "Mozilla Firefox";
       else
         return str.Split(';')[1];
     }
     public String sys(string str)
     {
       return (str.Split(';')[2]).Replace(")","");
     }
 
     public void setvister()
     {
       DateTime daynow=DateTime.Now;
       String ip=context.Request.UserHostAddress;
       string rurl=referrer;
       if (rurl==null || rurl=="")
         rurl="直接输入";
       if (url==null)
         url="直接输入";
       even.filepath=evenlogpath;
       String UserAgent=context.Request.UserAgent;
       if (context.Request.Cookies["vis"]==null && updateing==false)
       {
         updateing=true;
         even.greatlog(ip+mide+UserAgent+mide+rurl+mide+url);//建立访问信息
         context.Response.Cookies["vis"].Value="true";
         todayvister=(int)todayvister+1;
         updateing=false;
       }
       
     }
   }
 }

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
{Emgu}{C#}保存图片、视频等发布时间:2022-07-14
下一篇:
c# mongodb MongoCursor 中的遍历 (关键是_id字段)发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap