-------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
/// <summary>
///HttpModule 的摘要说明
/// </summary>
public class HttpModule: IHttpModule
{
public static string vaddr = "";
public static string tempAcid= "";
public static string pageUrl = "";
public HttpModule()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(application_BeginRequest);
application.EndRequest += new EventHandler(application_EndRequest);
}
void application_EndRequest(object sender, EventArgs e)
{
}
void application_BeginRequest(object sender, EventArgs e)
{
HttpApplication http = (HttpApplication)sender;
HttpContext context = http.Context;
context.Response.Write("Begin " + context.Request.RawUrl);
//string reqUrl = context.Request.RawUrl.ToLower();
#region 访问的地址记录
//int vaddrType = 0;//存在状态(0不存在相同的,1存在相同的)
//if (vaddr != "")
//{
// string[] vds = vaddr.Split('|');
// int count = vds.Length;
// for (int i = 0; i < count; i++)
// {
// if (vds[i] == reqUrl)
// {
// vaddrType = 1;
// }
// }
//}
添加
//if (vaddrType == 0)
//{
// vaddr += reqUrl + "|";
//}
#endregion
//if (HttpContext.Current.Request.ServerVariables["HTTP_REFERER"] != null)
//{
// pageUrl = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"].ToString();
//}
}
#region IHttpModule Members
public void Dispose()
{
}
#endregion
/// <summary>
/// 商品数量
/// </summary>
public string PageUrl
{
set { pageUrl = value; }
get { return pageUrl; }
}
}
--------------------------------------
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
}
void Application_End(object sender, EventArgs e)
{
//在应用程序关闭时运行的代码
}
void Application_Error(object sender, EventArgs e)
{
//在出现未处理的错误时运行的代码
}
void Session_Start(object sender, EventArgs e)
{
//在新会话启动时运行的代码
}
void Session_End(object sender, EventArgs e)
{
//在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式
//设置为 StateServer 或 SQLServer,则不会引发该事件。
//公司ID
if (Session["TempAcid"] != null && Session["TempVaddr"] != null)
{
string tempAcid = Session["TempAcid"].ToString();
//浏览过的网址地址
string vaddr = Session["TempVaddr"].ToString();
Statistice sta = new Statistice();
string[] compay = Session["TempAcid"].ToString().Split('|');
string com = "1";
for (int i = 0; i < compay.Length; i++)
{
object comp = sta.SelCompany(compay[i].ToString());
if (comp != null)
{
com = sta.SelCompany(compay[i].ToString()).ToString();
}
}
string ips = "";
if (Session["TempIP"] != null)
{
ips = Session["TempIP"].ToString();
}
//添加记录
if (sta.AddStatistice(com, ips, vaddr))
{
HttpModule.tempAcid = "";
HttpModule.vaddr = "";
Session["TempAcid"] = "";
Session["TempVaddr"] = "";
Session["TempIP"] = "";
}
}
}
</script>
----------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Second : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#region 来源网站
string pefereUurl = "";
if (Request.ServerVariables["HTTP_REFERER"] != null)
{
pefereUurl = Request.ServerVariables["HTTP_REFERER"].ToString();
}
if (Session["TempAcid"] != null)
{
//Session["TempAcid"] = pefereUurl + "|" + Session["TempAcid"].ToString();
int vaddrType = 0;//存在状态(0不存在相同的,1存在相同的)
string[] vds = Session["TempAcid"].ToString().Split('|');
int count = vds.Length;
for (int i = 0; i < count; i++)
{
if (vds[i] == pefereUurl)
{
vaddrType = 1;
}
}
//添加
if (vaddrType == 0)
{
Session["TempAcid"] = Session["TempAcid"].ToString() + "|" + pefereUurl;
}
}
else
{
Session["TempAcid"] = pefereUurl + "|";
}
#endregion
#region 浏览过的记录
if (Session["TempVaddr"] != null)
{
string vaddr = Session["TempVaddr"].ToString();
int vaddrType02 = 0;
string[] vds = vaddr.Split('|');
int count = vds.Length;
for (int i = 0; i < count; i++)
{
if (vds[i] == Request.RawUrl)
{
vaddrType02 = 1;
}
}
if (vaddrType02 == 0)
{
Session["TempVaddr"] = Session["TempVaddr"].ToString() + Request.RawUrl + "|";
}
}
else
{
Session["TempVaddr"] = Request.RawUrl + "|";
}
#endregion
#region 来源IP
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
Session["TempIP"] = result;
#endregion
}
}