在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
引用
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; } } } } |
请发表评论