好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > ASP.NET MVC 3實現訪問統計系統

ASP.NET MVC 3實現訪問統計系統

熱門標簽:西寧電銷外呼系統公司 南昌自動外呼系統線路 上海市三維地圖標注 辦公用地圖標注網點怎么操作 云南外呼系統代理 海東防封電銷卡 寧德防封版電銷卡 安陸市地圖標注app 聊城智能電銷機器人電話

運營網站,我們經常需要分析用戶的行為、用戶的習慣,用戶看重網站的哪一部分,哪一部分是對用戶有用的之類的信息,這些信息從哪里來,這時我們就需要用到訪問統計系統了。 網上已經有很多的統計系統,如站長統計、百度統計、谷歌分析之類的,別人的東西始終是別人的,為什么我們不自己實現統計的功能呢,而且自己寫的可以實現一些特殊的功能,如登錄,下單行為,能夠更好的融合自己的系統!

下面我們就用ASP.NET MVC 3來實現一個訪問統計系統!首先,使用程序生成一段js代碼,包括讀寫Cookie,及寫入一個唯一值到Cookie中,用來判斷獨立訪客者,再寫入訪問次數及上一個訪問頁面ID值;然后就是獲取客戶端時間,分辨率之類的。

string guid = Guid.NewGuid().ToString(); 
#region 生成js 
html.Append("function WriteCookie(cookieName, cookieValue, expiry) {"); //js寫cookie 
html.Append(" var expDate = new Date();"); 
html.Append(" if (expiry) {"); 
html.Append(" expDate.setTime(expDate.getTime() + expiry);"); 
html.Append(" document.cookie = cookieName + \"=\" + escape(cookieValue) + \"; path=/;expires=\" + expDate.toGMTString();"); 
html.Append(" }"); 
html.Append(" else {"); 
html.Append(" document.cookie = cookieName + \"=\" + escape(cookieValue) + \"; path=/;\""); 
html.Append(" }"); 
html.Append("}"); 
html.Append("function ReadCookie(name) {"); //js讀取cookie 
html.Append(" var cookieValue = \"\";"); 
html.Append(" var search = name + \"=\";"); 
 html.Append(" if (document.cookie.length >0) {"); 
html.Append(" offset = document.cookie.indexOf(search);"); 
html.Append(" if (offset != -1) {"); 
html.Append(" offset += search.length;"); 
html.Append(" end = document.cookie.indexOf(\";\", offset);"); 
html.Append(" if (end == -1)"); 
html.Append(" end = document.cookie.length;"); 
html.Append(" cookieValue = unescape(document.cookie.substring(offset, end))"); 
html.Append(" }"); 
html.Append(" }"); 
html.Append(" return cookieValue;"); 
html.Append("}"); 
html.Append("DateFormatString = function(datetime, format) {"); 
html.Append(" var year = datetime.getFullYear();"); 
html.Append(" var month = datetime.getMonth()+1;"); 
html.Append(" var date = datetime.getDate();"); 
html.Append(" var hour = datetime.getHours();"); 
html.Append(" var minutes = datetime.getMinutes();"); 
html.Append(" var second = datetime.getSeconds();"); 
html.Append(" format = format.replace(/YY/g, year).replace(/MM/g, month).replace(/DD/g, date).replace(/hh/g, hour).replace(/mm/g, minutes).replace(/ss/g, second);"); 
html.Append(" return format;"); 
html.AppendLine("}"); 
html.Append("var cookieEnabled = (navigator.cookieEnabled) ? true : false;"); //判斷瀏覽器是否支持cookie 
html.Append("if (typeof navigator.cookieEnabled == \"undefined\" !cookieEnabled) {"); 
html.Append(" document.cookie = \"testcookie\";"); 
html.Append(" cookieEnabled = (document.cookie == \"testcookie\") ? true : false;"); 
html.Append(" document.cookie = \"\";"); 
html.Append("}"); 
html.Append("var firstshow;"); 
html.Append("var visittotal;"); 
 html.Append("var isLogin;"); 
html.Append("var loginName;"); 
html.Append("if (cookieEnabled == true) {"); 
html.Append(" var HBCountShowCookie = ReadCookie(\"HBCountShowCookie\");"); //訪客瀏覽器唯一ID 
html.Append(" var HBCountVisitTotalCookie = ReadCookie(\"HBCountVisitTotalCookie\");"); //訪客瀏覽次數 
html.Append(" var HBClientIDCookie = ReadCookie(\"HBClientIDCookie\");"); //訪客上一個點擊頁面ID 
html.Append(" var HBLoginNameCookie = ReadCookie(\"HBLoginNameCookie\");"); //記錄登錄的用戶名 
html.Append(" if (HBCountShowCookie == \"\") {"); 
html.Append(" sparetime = 1000 * 60 * 60 * 24 * 3650;"); //有效期為一年 
html.Append(" WriteCookie('HBCountShowCookie', \"" + guid + "\", sparetime);"); 
html.Append(" HBCountShowCookie = ReadCookie(\"HBCountShowCookie\");"); 
html.Append(" firstshow = 1;"); 
html.Append(" }"); 
html.Append(" else {"); 
html.Append(" firstshow = 0;"); 
html.Append(" }"); 
html.Append(" if (HBCountVisitTotalCookie == \"\") {"); //游客統計 
html.Append(" sparetime = 1000 * 60 * 60 * 24 * 3650;"); 
html.Append(" WriteCookie('HBCountVisitTotalCookie', 1, sparetime);"); 
html.Append(" visittotal = 1;"); 
html.Append(" }"); 
html.Append(" else {"); 
html.Append(" if (firstshow == 1) {"); 
html.Append(" visittotal = parseInt(HBCountVisitTotalCookie) + 1;"); 
html.Append(" sparetime = 1000 * 60 * 60 * 24 * 3650;"); 
html.Append(" WriteCookie('HBCountVisitTotalCookie', visittotal, sparetime);"); 
html.Append(" }"); 
html.Append(" else {"); 
html.Append(" visittotal = parseInt(HBCountVisitTotalCookie);"); 
html.Append(" }"); 
html.Append(" }"); 
html.Append(" try {"); 
html.Append(" if (HBStat != undefined || HBStat.isLogin != undefined || HBStat.loginName != undefined) {"); //此為登錄用戶統計 
html.Append(" if (HBStat.isLogin == 1 HBStat.loginName != \"\") {"); 
html.Append(" sparetime = 1000 * 60 * 60 * 24 * 120;"); 
html.Append(" WriteCookie('HBLoginNameCookie', HBStat.loginName, sparetime);"); 
html.Append(" HBLoginNameCookie = ReadCookie(\"HBLoginNameCookie\");"); 
html.Append(" }"); 
html.Append(" isLogin=HBStat.isLogin;"); 
html.Append(" }"); 
html.Append(" else{isLogin=0;}"); 
html.Append(" }"); 
html.Append(" catch (e) { isLogin=0; }"); 
html.Append(" loginName=HBLoginNameCookie;"); 
html.Append("} else {"); //不支持cookie 
html.Append(" firstshow = 0;"); 
html.Append(" visittotal = 1;"); 
 html.Append(" var HBCountShowCookie = \"\";"); 
html.Append(" isLogin=0;"); 
html.Append(" loginName=\"\";"); 
html.Append("}"); 
html.Append("var ly = escape(document.referrer);"); 
html.Append("var currweb = escape(location.href);"); 
html.Append("var d = new Date();"); 
html.Append("var currdate=DateFormatString(d,'YY-MM-DD hh:mm:ss');"); 
html.Append("var screenwidth=screen.width;"); 
html.Append("var screenheight=screen.height;"); 
html.Append("var screencolordepth=screen.colorDepth;"); 
html.Append("document.write('script src=\"" + websiteUrl + "CountGet/?SiteID=" + SiteID + "assort=" + assort + "isLogin='+isLogin+'loginName='+loginName+'FirstShow='+firstshow+'VisitTotal='+visittotal+'Ly='+ly+'CurrWeb='+currweb+'cookid='+HBCountShowCookie+'screenwidth=' + screenwidth + 'screenheight=' + screenheight + 'screencolordepth=' + screencolordepth + 'currdate='+currdate+'ranstr=' + Math.random() + '\">/script>');"); 
#endregion 

生成之后再去執行下一個Action,用來寫入一些統計數據,如客戶端IP,瀏覽器信息,訪問頁面來源,當前頁、訪問時間、離開時間等!根據上一個訪問頁面地址、當前地址及上一個訪問頁面ID來判斷是否是刷新操作還是新的訪問頁面,如果是刷新操作則寫入刷新時間,否則寫入上一個頁面的離開時間,由于js的跨域問題,

if (assort.Equals(0)) 
{ 
ly = Request.QueryString["Ly"]; //獲取來源URL 
currWeb = Request.QueryString["CurrWeb"]; //獲取當前URL 
} 
else 
{ 
ly = Request.ServerVariables["Http_Referer"]; 
currWeb = ly; 
} 
string firstShow = Request.QueryString["FirstShow"]; //是否第一次訪問 
string visitTotal = Request.QueryString["VisitTotal"]; //獲取瀏覽次數 
string ip = Helper.Utils.ClientIP(); //獲取客戶端IP地址 
string strAgent = Request.ServerVariables["HTTP_USER_AGENT"]; 
bool isAlexa = false; 
if (strAgent.IndexOf("alexa") >-1) //判斷是否安裝alexa工具欄 
isAlexa = true; 
string browerName = Request.Browser.Browser; //瀏覽器名稱 
string browerVersion = Request.Browser.Version; //瀏覽器版本 
string os = Helper.Utils.GetClientOS(); //客戶端操作系統 
string langage = Helper.Utils.GetLangage(); //客戶端語言 
string spider = Helper.Utils.GetSpiderBot(); //搜索引擎爬蟲信息 
bool isSpider = false; 
if (!string.IsNullOrEmpty(spider)) 
isSpider = true; 
HttpContext.Application.Lock(); 
ClickDataAccess clientBasic = new ClickDataAccess(); 
 //刷新操作 需要根據上一個地址和當前地址 來判斷 
if (HttpContext.Application["HBCurrWeb_" + SiteID] != null 
HttpContext.Application["HBCurrWeb_" + SiteID].ToString().Equals(currWeb) 
HttpContext.Application["HBLy_" + SiteID] != null 
HttpContext.Application["HBLy_" + SiteID].ToString().Equals(ly) 
HttpContext.Application["HBClientId_" + SiteID] != null) 
{ 
clientBasic.UpdateForRefresh(HttpContext.Application["HBClientId_" + SiteID]); 
//Helper.Utils.CreateFile("~/Log/", DateTime.Now.ToString("yyyyMMddHHmmssffff") + "_" + SiteID + "刷新.txt", writetext.ToString()); 
} 
else 
{ 
if (HttpContext.Application["HBClientId_" + SiteID] != null) //如果存在上一個頁面的ID值則寫入離開時間 
clientBasic.UpdateForLeaveTime(HttpContext.Application["HBClientId_" + SiteID]); 
ClickAndVisitorsDataAccess clientData = new ClickAndVisitorsDataAccess(); 
string[] outParam = clientData.Save(client); 
if (!string.IsNullOrEmpty(outParam[0])) 
HttpContext.Application["HBPublicId_" + SiteID] = outParam[0]; 
if (!string.IsNullOrEmpty(outParam[1])) 
{ 
HttpContext.Application["HBClientId_" + SiteID] = outParam[1]; 
javaScript = "WriteCookie('HBClientIDCookie'," + int.Parse(outParam[1]) + ");"; 
} 
HttpContext.Application["HBCurrWeb_" + SiteID] = currWeb; 
HttpContext.Application["HBLy_" + SiteID] = ly; 
} 
HttpContext.Application.UnLock(); 
#endregion 


這里使用Application來存儲對象,當然也可以使用緩存類來做.

暫時沒有解決離開當前網站時的離開時間,當然如果訪問統計系統的域名和被統計的網站域名是同一個頂級域名,則可以做到這點!

訪問統計系統的后臺使用存儲過程來統計分析數據,暫時只寫了一部分功能,僅供大家學習參考!

您可能感興趣的文章:
  • asp.net 圖片驗證碼的HtmlHelper
  • C# MVC模式中應該怎樣區分應用程序邏輯(Controller層)和業務邏輯(Model層)?
  • 實現Asp.net mvc上傳頭像加剪裁功能
  • 初識ASP.NET Mvc5+EF7的奇妙之旅
  • ASP.NET MVC中圖表控件的使用方法
  • windows2003 IIS6 部署MVC3和MVC4程序的方法
  • ASP.NET Mvc開發之EF延遲加載
  • ASP.NET Mvc開發之查詢數據
  • ASP.NET Mvc開發之刪除修改數據
  • ASP.NET MVC中HtmlHelper控件7個大類中各個控件使用詳解

標簽:崇左 南寧 衢州 青海 平涼 贛州 洛陽 汕尾

巨人網絡通訊聲明:本文標題《ASP.NET MVC 3實現訪問統計系統》,本文關鍵詞  ASP.NET,MVC,實現,訪問,統計,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《ASP.NET MVC 3實現訪問統計系統》相關的同類信息!
  • 本頁收集關于ASP.NET MVC 3實現訪問統計系統的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 无码人妻av久久久一区二区三区| 握住焰灵姬硕大的双乳h| 年轻的护士3高潮电影| 天天躁日日躁狠狠躁到发狂| 野花电影高清完整版在线观看| 深夜福利免费在线观看| 欧美精品区| 太粗硬老寡妇受不了| 久久国产精品鲁丝片| 91高端极品外围女在线观看| 欧美人与日本人xx| gogo西西人体大尺度大胆喷水 | 日韩一级高清毛片收藏推荐| 国产精品96久久久久久久| 一女被多男大3p视频| 啊轻点灬太粗嗯太深了凯约| 国产精品刺激对白51| 扒开美女视频网站| 欧美精品久久久久久一级毛片舌吻 | 夜鲁夜鲁很鲁视频在线观看 | x8x8在线| 膀胱调教灌水惩罚bl| 边摸边吃奶边做好爽视频| 成人免费毛片AAAAAA片| 一个人看的视频www视频| a级**毛片看久久| 睡了美女丝袜白嫩老师| 女澡堂洗澡高清播放视频| 嗯啊舒服用力| 扒开双腿猛进入18p| 女律师的堕落故事完整版| 小可的奶水全文阅读目录TXT| 国产婬仑久久久久久久| 皇帝脔宠h粗大| 国产精品v欧美精品v日韩 | 国产一级在线播放| 91福利视频一区| 成 人 黄 色 网站 小说APP| 小水好湿?好紧?太爽了| 成人做爰高潮片免费看APP | 国产AV精品大屁股妖精视频|