这东西 
好像每页都得添加些代码 操作数据库代码 就insert into 之类的

解决方案 »

  1.   

    结合数据库,load 事件里面 插入到数据库里面
      

  2.   

    上面都说得很具体了
    而且这个东西 访问量大了 很占服务器资源 
    建议还是免了...或者只统计个别页面的访问我有一个asp的站点访问的统计日志的代码
      

  3.   

    在page_load里面写个方法完成你的需要
      

  4.   

    做个HttpHandler处理程序就可以了.
      

  5.   

    我这样做的,但是结果不理想
    //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
      

  6.   

    我这样做的,但是结果不理想
    //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
      

  7.   

    我这样做的,但是结果不理想
    //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
      

  8.   

    就象jjhlover(菜花)那样差不多.写个HTTP处理程序就可以了!
      

  9.   

    using System;
    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>
    我没测试过.你试试看!
      

  10.   

    string referencepage=objContext.Request.ServerVariables["HTTP_REFERER"].ToString();
    referencepage为啥一直为null呀?
      

  11.   

    string referencepage=objContext.Request.ServerVariables["HTTP_REFERER"].ToString();
    referencepage为啥一直为null呀?
      

  12.   

    string referencepage=objContext.Request.ServerVariables["HTTP_REFERER"].ToString();
    referencepage为啥一直为null呀?