H.ashx部分代碼
創(chuàng)新互聯(lián)專注于建湖企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),商城網(wǎng)站定制開發(fā)。建湖網(wǎng)站建設(shè)公司,為建湖等地區(qū)提供建站服務(wù)。全流程按需求定制設(shè)計,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
namespace DHCC.OCCS.Track
{
///
/// 用戶跟蹤主程序
///
public class H : IHttpHandler, IRequiresSessionState
{
public void Proce***equest(HttpContext context)
{
using (DB.Entities db = new DB.Entities())
{
context.Response.ContentType = "text/plain";
HttpRequest request = context.Request;//生成新對象
try
{
if (request.Params["jishu"] == "1")
{
DB.BrowserOS os = new DB.BrowserOS();
DB.BrowserLang lang = new DB.BrowserLang();
DB.BrowserType type = new DB.BrowserType();
DB.BrowserScreen screen = new DB.BrowserScreen();
DB.SiteTrack st = new DB.SiteTrack();
//獲取操作系統(tǒng)信息
string os_os = "";
string os_os1 = "";
if (request.UserAgent.IndexOf("Windows NT 6.1") != -1)//通過useragent判斷類型
{
os_os1 = "window7";
os_os = "window7_" + request.QueryString["os"];
}
else if (request.UserAgent.IndexOf("Windows NT 6.2") != -1)
{
os_os1 = "window8";
os_os = "window8_" + request.QueryString["os"];
}
else if (request.UserAgent.IndexOf("Windows NT 6.0") != -1)
{
os_os1 = "Vista";
os_os = "Vista_" + request.QueryString["os"];
}
else if (request.UserAgent.IndexOf("Windows NT 5.0") != -1)
{
os_os1 = "Windows2000";
os_os = "Windows2000_" + request.QueryString["os"];
}
else if (request.UserAgent.IndexOf("Windows NT 5.1") != -1)
{
os_os1 = "Windows XP";
os_os = "Windows XP_" + request.QueryString["os"];
}
else if (request.UserAgent.IndexOf("Windows NT 5.2") != -1)
{
os_os1 = "Windows XP x64";
os_os = "Windows XP x64" + request.QueryString["os"];
}
else if (request.UserAgent.IndexOf("Windows NT 6.3") != -1)
{
os_os1 = "Windows 8.1";
os_os = "Windows 8.1_" + request.QueryString["os"];
}
var o = db.BrowserOS.FirstOrDefault(c => c.os == os_os);//判斷數(shù)據(jù)是否存在
if (o == null)//數(shù)據(jù)不存在添加到數(shù)據(jù)庫中
{
if (os_os.IndexOf("32") != -1)
{
switch (os_os1)//按操作系統(tǒng)類型添加數(shù)據(jù)
{
case "window7": os.comment = "32位window7/Windows Server 2008R2系統(tǒng)";
break;
case "window8": os.comment = "32位window8/Windows Phone/Windows Server 2012系統(tǒng)";
break;
case "Vista": os.comment = "32位Vista/Windows Server 2008系統(tǒng)";
break;
case "Windows2000": os.comment = "32位Windows2000系統(tǒng)";
break;
case "Windows XP": os.comment = "32位Windows XP系統(tǒng)";
break;
case "Windows XP x64": os.comment = "32位Windows XP x64 Edition/Windows Server 2003/Windows Server 2003 R2系統(tǒng)";
break;
case "Windows 8.1": os.comment = "32位Windows 8.1/Windows Server 2012 R2系統(tǒng)";
break;
default:
break;
}
}
else if (os_os.IndexOf("64") != -1)
{
switch (os_os1)
{
case "window7": os.comment = "64位window7/Windows Server 2008R2系統(tǒng)";
break;
case "window8": os.comment = "64位window8/Windows Phone/Windows Server 2012系統(tǒng)";
break;
case "Vista": os.comment = "64位Vista/Windows Server 2008系統(tǒng)";
break;
case "Windows2000": os.comment = "64位Windows2000系統(tǒng)";
break;
case "Windows XP": os.comment = "64位Windows XP系統(tǒng)";
break;
case "Windows XP x64": os.comment = "64位Windows XP x64 Edition/Windows Server 2003/Windows Server 2003 R2系統(tǒng)";
break;
case "Windows 8.1": os.comment = "64位Windows 8.1/Windows Server 2012 R2系統(tǒng)";
break;
default:
break;
}
}
os.os = os_os;
db.BrowserOS.Add(os);
st.os = os.id;
}
else//如果數(shù)據(jù)存在
{
st.os = o.id;
}
string lang_lang = request.QueryString["lang"];//瀏覽器語言
var l = db.BrowserLang.FirstOrDefault(c => c.lang == lang_lang);
if (l == null)
{
switch (lang_lang)
{
case "zh-cn": lang.comment = "簡體中文";
break;
default:
break;
}
lang.lang = lang_lang;
db.BrowserLang.Add(lang);
st.lang = lang.id;
}
else
{
st.lang = l.id;
}
//用戶分辨率
string screen_screen = request.QueryString["screen"];
var sc = db.BrowserScreen.FirstOrDefault(c => c.screen == screen_screen);
if (sc == null)
{
screen.screen = screen_screen;
db.BrowserScreen.Add(screen);
st.screen = screen.id;
}
else
{
st.screen = sc.id;
}
//瀏覽器類型
string type_type = "";
if (request.UserAgent.IndexOf("MSIE 9.0") != -1)
{
type_type = "IE9";
}
else if (request.UserAgent.IndexOf("MSIE 8.0") != -1)
{
type_type = "IE8";
}
else if (request.UserAgent.IndexOf("MSIE 7.0") != -1)
{
type_type = "IE7";
}
else if (request.UserAgent.IndexOf("MSIE 6.0") != -1)
{
type_type = "IE6";
}
else if (request.UserAgent.IndexOf("MSIE 10.0") != -1)
{
type_type = "IE10";
}
else if (request.UserAgent.IndexOf("IE 11.0") != -1)
{
type_type = "IE11";
}
else if (request.UserAgent.IndexOf("Chrome") != -1)
{
type_type = "chrome";
}
else if (request.UserAgent.IndexOf("Firefox") != -1)
{
type_type = "Firefox";
}
else if (request.UserAgent.IndexOf("Opera") != -1)
{
type_type = "Opera";
}
else if (request.UserAgent.IndexOf("360SE") != -1)
{
type_type = "360";
}
var ty = db.BrowserType.FirstOrDefault(c => c.type == type_type);
if (ty == null)
{
switch (type_type)
{
case "IE9": type.comment = "IE9瀏覽器";
break;
case "IE8": type.comment = "IE8瀏覽器";
break;
case "360": type.comment = "360瀏覽器";
break;
case "Opera": type.comment = "Opera瀏覽器";
break;
case "Firefox": type.comment = "Firefox瀏覽器";
break;
case "IE11": type.comment = "IE11瀏覽器";
break;
case "IE10": type.comment = "IE10瀏覽器";
break;
case "IE7": type.comment = "IE7瀏覽器";
break;
case "IE6": type.comment = "IE6瀏覽器";
break;
case "chrome": type.comment = "chrome瀏覽器";
break;
default:
break;
}
type.type = type_type;
db.BrowserType.Add(type);
st.type = type.id;
}
else
{
st.type = ty.id;
}
st.curUrl = request.Params["curUrl"];
st.fromUrl = request.Params["fromUrl"];
st.pagein = Convert.ToDateTime(request.Params["pagein"]);//進(jìn)入頁面時間
st.ip = request.UserHostAddress;//客戶端ip地址
st.id = Guid.NewGuid().ToString("N");//隨機(jī)分配id
db.SiteTrack.Add(st);
context.Response.Write(st.id);
}
else if (request.Params["jishu"] == "2")//離開時間
{
string id_id = request.Params["id"];
var st1 = db.SiteTrack.FirstOrDefault(c => c.id == id_id);
st1.pageout = Convert.ToDateTime(request.Params["pageout"]);
}
db.SaveChanges();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}