代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.Net
】
网站统计分析
作者:
Dezai.CN
/ 发布于
2012/2/20
/
467
<div>using System; using System.Collections.Generic; using System.Text; using AjaxPro; using System.Collections.Specialized; using System.Text.RegularExpressions; using System.Web; using System.Data.SqlClient; using System.Data; namespace LTP.Common { /// <summary> /// 韩保新于2010年4月 /// 此类获取用户信息 /// 主要用于以后网站分析统计 /// </summary> public class statistic { private int _screenHeight = 0; private int _screenWidth = 0; private string _laiyuanUrl = ""; public statistic() { } /// <summary> /// 得到浏览器版本 /// </summary> public string Browser { get { return commom.getBrowser(); } } /// <summary> /// 得到操作系统名称 /// </summary> public string OsName { get { return commom.getOSName(); } } /// <summary> /// 得到用户iP地址 /// </summary> public string UserIp { get { return commom.GetRealIP(); } } /// <summary> /// 来源url /// </summary> public string LaiyuanUrl { set { _laiyuanUrl = value; } get { return _laiyuanUrl; } } public string HostName { get { Uri u = new Uri(LaiyuanUrl); return u.Host.ToString().ToLower(); } } /// <summary> /// 当前url /// </summary> public string CurrentPage { get { return HttpContext.Current.Request.UrlReferrer.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.UrlReferrer.PathAndQuery.ToString(); } } /// <summary> /// Url方案名称 /// </summary> private string scheme { get { string s = "http://"; if (HttpContext.Current.Request.Url.Scheme == System.Uri.UriSchemeHttps) s = "https://"; return s; } } /// <summary> /// 屏幕高度 /// </summary> public int ScreenHeight { set { _screenHeight = value; } get { return _screenHeight; } } /// <summary> /// 屏幕宽度 /// </summary> public int ScreenWidth { set { _screenWidth = value; } get { return _screenWidth; } } /// <summary> /// 得到url编码 /// </summary> /// <param name="url"></param> /// <returns></returns> private string getCode() { Uri u = new Uri(LaiyuanUrl); string host = u.Host.ToString().ToLower(); string query = u.PathAndQuery; string url = scheme + host + query; NameValueCollection nvc = commom.ParseUrl(url); string bianma = "UTF-8"; string gb2312 = "<a href="http://www.baidu.com,www1.baidu.com,www.baidu.com.,www.baidu.com.hk,202.108.22.5,119.75.213.61,zhidao.baidu.com,news.baidu.com,cache.baidu.com,tieba.baidu.com,cpro.baidu.com,114search.118114.cn,www.soso.com,web.gougou.com,www.sogou.com,news.soso.com,news.youdao.com,hap1.ucweb.com.cn">www.baidu.com,www1.baidu.com,www.baidu.com.,www.baidu.com.hk,202.108.22.5,119.75.213.61,zhidao.baidu.com,news.baidu.com,cache.baidu.com,tieba.baidu.com,cpro.baidu.com,114search.118114.cn,www.soso.com,web.gougou.com,www.sogou.com,news.soso.com,news.youdao.com,hap1.ucweb.com.cn</a>"; if (gb2312.Contains(host)) bianma = "GB2312"; if (nvc != null) { #region 处理hap1.ucweb.com.cn,如:hap1.ucweb.com.cn/baidu_groups/web/http/m7.baidu.com/coop/s?pn=6&word=%E5%B9%BF%E6%B1%89%E6%9C%89%E6%B2%A1%E8%8B%B1%E8%AF%AD%E8%BF%87%E7%BA%A7%E8%80%83%E8%AF%95%E7%9A%84%E5%9F%B9%E8%AE%AD%E7%8F%AD&rn=6&from=2001f。默认的是gb2312,如果pn!="" and tn="" 那么编码就是utf-8 if (host == "hap1.ucweb.com.cn") { bool mark1 = false; bool mark2 = false; for (int i = 0; i < nvc.Count; i++) {</div> <div> if (nvc.Keys[i].ToString().Trim() == "pn" && nvc[i] != "") { mark1 = true; } if (nvc.Keys[i].ToString().Trim() == "tn" && nvc[i] != "") { mark2 = true; } <div> } if (mark1 && !mark2) bianma = "UTF-8"; } #endregion else { for (int i = 0; i < nvc.Count; i++) { if (nvc.Keys[i].ToString().Trim() == "ie") { if (nvc[i] != "") bianma = nvc[i]; } } } } return bianma; } /// <summary> /// 得到来源的关键字,主要用于搜索引擎 /// </summary> /// <param name="url"></param> /// <param name="code"></param> /// <returns></returns> public string laiyuanKeyName() { string keyName = ""; if (LaiyuanUrl == null || LaiyuanUrl == "") return keyName; string code = getCode(); NameValueCollection nvc = commom.ParseUrl(LaiyuanUrl); string strkeyName = ",wd,word,kw,q,search,url,query,p,w,"; if (nvc != null) { string mark = ""; for (int i = 0; i < nvc.Count; i++) { if (strkeyName.IndexOf("," + nvc.Keys[i].ToString().Trim() + ",") > -1 && mark != nvc[i]) { keyName += System.Web.HttpUtility.UrlDecode(nvc[i], System.Text.UnicodeEncoding.GetEncoding(code)); mark = System.Web.HttpUtility.UrlDecode(nvc[i], System.Text.UnicodeEncoding.GetEncoding(code)); } } } return keyName; } } public class commom { /// <summary> /// 获取用户真实ip /// </summary> /// <returns></returns> public static string GetRealIP() { string ip; try { HttpRequest request = HttpContext.Current.Request;</div> <div> if (request.ServerVariables["HTTP_VIA"] != null) { ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim(); } else { ip = request.UserHostAddress; } } catch (Exception e) { throw e; } <div> return ip; } /// <summary> /// 获取操作系统名称 /// </summary> /// <param name="userAgent"></param> /// <returns></returns> public static string getOSName() { HttpRequest request = HttpContext.Current.Request; string userAgent = request.UserAgent.ToString(); string osVersion = "未知"; if (userAgent.Contains("NT")) { if (userAgent.Contains("NT 6.1")) { return "Windows 7"; } if (userAgent.Contains("NT 6.0")) { return "Windows Vista/Server 2008"; } if (userAgent.Contains("NT 5.2")) { return "Windows Server 2003"; } if (userAgent.Contains("NT 5.1")) { return "Windows XP"; } if (userAgent.Contains("NT 5")) { return "Windows 2000"; } if (userAgent.Contains("NT 4")) { return "Windows NT4"; } return "Windows 其他"; } if (userAgent.Contains("Me")) { return "Windows Me"; } if (userAgent.Contains("Windows 98")) { return "Windows 98"; } if (userAgent.Contains("95")) { return "Windows 95"; } if (userAgent.Contains("Mac")) { return "Mac"; } if (userAgent.Contains("Unix")) { return "UNIX"; } if (userAgent.Contains("Linux")) { return "Linux"; } if (userAgent.Contains("SunOS")) { return "SunOS"; } return osVersion; } /// <summary> /// 获取用户浏览器名称和版本号 /// </summary> /// <returns></returns> public static string getBrowser() { HttpRequest request = HttpContext.Current.Request; return request.Browser.Browser + request.Browser.Version; } /// <summary> /// 获取url参数和值,参数为nvc.Keys[i],对应的值为nvc[i] /// </summary> /// <param name="url"></param> /// <returns></returns> public static NameValueCollection ParseUrl(string pUrl) { if (pUrl == null) return null;</div> <div> NameValueCollection nvc = new NameValueCollection(); int questionMarkIndex = pUrl.IndexOf('?'); if (questionMarkIndex == -1) { return null; } if (questionMarkIndex == pUrl.Length - 1) return null; string ps = pUrl.Substring(questionMarkIndex + 1);</div> <div> // 开始分析参数对 Regex re = new Regex(@"(^|&)?(/w+)=([^&]+)(&|$)?", RegexOptions.Compiled); MatchCollection mc = re.Matches(ps);</div> <div> foreach (Match m in mc) { nvc.Add(m.Result("$2"), m.Result("$3")); } return nvc; } } public class ajaxsta { [AjaxPro.AjaxMethod] public string statitcs(int width, int height, string url) { try { if (url != "") { if (!url.Contains("edu.eastday.com")) { statistic sta = new statistic(); sta.ScreenHeight = height; sta.ScreenWidth = width; sta.LaiyuanUrl = url; string type = "推荐网站"; if (sta.laiyuanKeyName() != "") type = "搜索引擎"; Assistant.SetCookie("laiyuan", sta.LaiyuanUrl); Assistant.SetCookie("laiyuan2", sta.CurrentPage); excuteSql(sta.laiyuanKeyName(), commom.GetRealIP(), sta.HostName, commom.getBrowser(), commom.getOSName(), width.ToString() + "x" + height.ToString(), sta.CurrentPage, type, sta.LaiyuanUrl); exculteFlow(int.Parse(Assistant.GetCookie("laiyuanID")), sta.CurrentPage, url, false); } else { if (Assistant.GetCookie("laiyuanID") != string.Empty) { string url0 = HttpContext.Current.Request.UrlReferrer.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.UrlReferrer.PathAndQuery.ToString(); exculteFlow(int.Parse(Assistant.GetCookie("laiyuanID")), url0, url, false); Assistant.SetCookie("laiyuanID", Assistant.GetCookie("laiyuanID"), 0.1);//更新cookie时间 } else { if (url.IndexOf("informations") >= 0) { Assistant.SetCookie("laiyuan", "infos." + ConfigHelper.GetConfigString("Domain")); Assistant.SetCookie("laiyuan2", url); } } } } else { Assistant.SetCookie("laiyuan2", ConfigHelper.GetConfigString("Domain") + HttpContext.Current.Request.RawUrl.ToString()); string url0 = HttpContext.Current.Request.UrlReferrer.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.UrlReferrer.PathAndQuery.ToString(); //string strSql = "insert into LaiYuanNews(keyName,userip,hostName,browser,OsName,DPI,LandingPage,Adddate,originType,originUrl) values ('','" + commom.GetRealIP() + "','','" + commom.getBrowser() + "','" + commom.getOSName() + "','" + width.ToString() + "x" + height.ToString() + "','" + url + "','" + DateTime.Now.ToString() + "','直接流量','')"; excuteSql("", commom.GetRealIP(), "", commom.getBrowser(), commom.getOSName(), width.ToString() + "x" + height.ToString(), url0, "直接流量", ""); } } catch (Exception e) { return "错误!"; } return "成功!"; } [AjaxPro.AjaxMethod] public string statitcsFlow(string url) { if (Assistant.GetCookie("laiyuanID") != string.Empty) { string url0 = HttpContext.Current.Request.UrlReferrer.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.UrlReferrer.PathAndQuery.ToString(); exculteFlow(int.Parse(Assistant.GetCookie("laiyuanID")), url0, url, true); } return ""; } }
试试其它关键字
网站统计分析
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3