ASP.NET访客计数器 [英] ASP.NET Visitors counter

查看:112
本文介绍了ASP.NET访客计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造了我的网页上的计数器。什么wan't实现的是,每次用户访问我的asp.net应用程序,它自己的数据存储到数据库中。我使用的Global.asax和事件的Application_Start。这里是我的code。

I am creating a counter for my webpage. What wan't to achieve is that every time user visits my asp.net application, it stores his data into database. I am using Global.asax and event Application_Start. Here is my code .

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);

        WebpageCounter.SaveVisitor(new WebpageVisitor()
        {
            VisitorIP = HttpContext.Current.Request.UserHostAddress,
            VisitedOn = DateTime.Now
        });
    }

但它从来没有任何东西存储到数据库中。该功能SaveVisitor已经过测试,是功能。有什么建议么 ?

But it never stores anything into database. The function SaveVisitor has been tested and it is functional. Any suggestions ?

感谢

推荐答案

的Application_Start只有在运行时创建的过程 - 不是每个访问

Application_Start is runs only when process created - not every visit.

您可以使用的Application_BeginRequest来代替。

You can use Application_BeginRequest instead.

这篇关于ASP.NET访客计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆