这东西
好像每页都得添加些代码 操作数据库代码 就insert into 之类的
好像每页都得添加些代码 操作数据库代码 就insert into 之类的
解决方案 »
- ASP.NET 开发视频会议
- asp.net下App_Code文件下 dbml文件
- ubb替换空格和换行问题
- 去除word样式的正则或者办法不要JS 我在。cs文件里写
- 使用response.redirect()调用iframe,如何象定义链接那样可以设置Main,使网页在本页面中的iframe显示?
- 请问高手 怎么获取本月月初和月底时间
- 题,会的帮忙了,谢谢
- JAVASCRIPT高手进来看看这个问题
- 请问各位高手我是一个菜鸟,谁教下怎么入门啊,或者推荐个教程给我,跪谢了
- 如何获得所有页面变量传递?
- 使用“控件.Visible = false;”是否虽然没显示,也同样消耗了服务器资源?
- 怎么获取模板列的值
而且这个东西 访问量大了 很占服务器资源
建议还是免了...或者只统计个别页面的访问我有一个asp的站点访问的统计日志的代码
//web.config
<system.web>
<httpModules>
<add name="SecurityHttpModule" type="Joel.Net.SecurityHttpModule"/>
<add name="LogHttpModule" type="LogHttpModule"/>
</httpModules>//LogHttpModule
public class LogHttpModule:IHttpModule
{
public LogHttpModule()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public void Init(System.Web.HttpApplication context)
{
context.AuthenticateRequest += new
EventHandler(this.LogRequest);
} private void LogRequest(Object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpRequest request = application.Context.Request;
HttpResponse response = application.Context.Response; DateTime dat = DateTime.Now;
string ip = request.UserHostAddress;
string userName = "";//application.Context.User.Identity.Name;
string something = "access page " + request.Url.LocalPath;
MyFrame.log(dat, ip, userName, something);
} public void Dispose() { }
}//
public class MyFrame
{
private static object objLock = new object();
public MyFrame()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public static void log(DateTime tim, string ip, string userName, string something)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("Time:");
sb.Append(tim);
sb.Append("\n");
sb.Append("IP:");
sb.Append(ip);
sb.Append("\n");
sb.Append("User:");
sb.Append(userName);
sb.Append("\n");
sb.Append("Action:");
sb.Append(something);
sb.Append("\n");
sb.Append("\n"); lock (objLock)
{
string path = HttpContext.Current.Server.MapPath("log.log");
StreamWriter sw = File.AppendText(path); sw.Write(sb.ToString());
sw.Close();
sw = null;
}
}
}不理想的结果:
//Log.log
Time:2007-04-03 10:59:46
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axd
//web.config
<system.web>
<httpModules>
<add name="SecurityHttpModule" type="Joel.Net.SecurityHttpModule"/>
<add name="LogHttpModule" type="LogHttpModule"/>
</httpModules>//LogHttpModule
public class LogHttpModule:IHttpModule
{
public LogHttpModule()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public void Init(System.Web.HttpApplication context)
{
context.AuthenticateRequest += new
EventHandler(this.LogRequest);
} private void LogRequest(Object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpRequest request = application.Context.Request;
HttpResponse response = application.Context.Response; DateTime dat = DateTime.Now;
string ip = request.UserHostAddress;
string userName = "";//application.Context.User.Identity.Name;
string something = "access page " + request.Url.LocalPath;
MyFrame.log(dat, ip, userName, something);
} public void Dispose() { }
}//
public class MyFrame
{
private static object objLock = new object();
public MyFrame()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public static void log(DateTime tim, string ip, string userName, string something)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("Time:");
sb.Append(tim);
sb.Append("\n");
sb.Append("IP:");
sb.Append(ip);
sb.Append("\n");
sb.Append("User:");
sb.Append(userName);
sb.Append("\n");
sb.Append("Action:");
sb.Append(something);
sb.Append("\n");
sb.Append("\n"); lock (objLock)
{
string path = HttpContext.Current.Server.MapPath("log.log");
StreamWriter sw = File.AppendText(path); sw.Write(sb.ToString());
sw.Close();
sw = null;
}
}
}不理想的结果:
//Log.log
Time:2007-04-03 10:59:46
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axd
//web.config
<system.web>
<httpModules>
<add name="SecurityHttpModule" type="Joel.Net.SecurityHttpModule"/>
<add name="LogHttpModule" type="LogHttpModule"/>
</httpModules>//LogHttpModule
public class LogHttpModule:IHttpModule
{
public LogHttpModule()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public void Init(System.Web.HttpApplication context)
{
context.AuthenticateRequest += new
EventHandler(this.LogRequest);
} private void LogRequest(Object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpRequest request = application.Context.Request;
HttpResponse response = application.Context.Response; DateTime dat = DateTime.Now;
string ip = request.UserHostAddress;
string userName = "";//application.Context.User.Identity.Name;
string something = "access page " + request.Url.LocalPath;
MyFrame.log(dat, ip, userName, something);
} public void Dispose() { }
}//
public class MyFrame
{
private static object objLock = new object();
public MyFrame()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public static void log(DateTime tim, string ip, string userName, string something)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("Time:");
sb.Append(tim);
sb.Append("\n");
sb.Append("IP:");
sb.Append(ip);
sb.Append("\n");
sb.Append("User:");
sb.Append(userName);
sb.Append("\n");
sb.Append("Action:");
sb.Append(something);
sb.Append("\n");
sb.Append("\n"); lock (objLock)
{
string path = HttpContext.Current.Server.MapPath("log.log");
StreamWriter sw = File.AppendText(path); sw.Write(sb.ToString());
sw.Close();
sw = null;
}
}
}不理想的结果:
//Log.log
Time:2007-04-03 10:59:46
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axdTime:2007-04-03 10:59:47
IP:127.0.0.1
User:
Action:access page /Menu/WebResource.axd
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;/// <summary>
/// Log 的摘要说明
/// </summary>
namespac PageLog
{
public class Log:IHttpModule
{
public Log()
{
//
// TODO: 在此处添加构造函数逻辑
//
} #region IHttpModule 成员 public void Dispose()
{
} public void Init(HttpApplication myApp)
{
myApp.BeginRequest+=new EventHandler(this.OnEnter);
} #endregion public void OnEnter(object s,EventArgs e)
{
HttpApplication objApp = (HttpApplication)s;
HttpContext objContext = objApp.Context;
string strPath = objContext.Request.Path.ToLower();
if (strPath.Substring(strPath.Length - 4, 4) == "*.axd")
return;
strPath = strPath.Substring(0, strPath.LastIndexOf(".") - 1);
string tim = objContext.Timestamp.ToString(); ;
string type=objContext.Request.Browser.Type;
string hostname=objContext.Request.UserHostName;
string referencepage=objContext.Request.ServerVariables["HTTP_REFERER"].ToString();///在将这些数据写入数据库
}
}
}然后将这个类编译:csc/t:library/r:System.dll,system.web.dll log.cs
在Web.Config里面加入如下
<configuration>
<system.web>
<httpModules>
<add name="log"
type="PageLog.Log,Log" />
</httpModules>
</system.web>
</configuration>
我没测试过.你试试看!
referencepage为啥一直为null呀?
referencepage为啥一直为null呀?
referencepage为啥一直为null呀?