asp.net的访客数(在线用户)今天 - 昨天在.net 4 [英] asp.net visitors count (online users) for today-yesterday in .net 4

查看:147
本文介绍了asp.net的访客数(在线用户)今天 - 昨天在.net 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用程序写了以下访问者代码(在线用户):

i wrote the below codes for visitors count (online users) for my application :

参考:

http://aspdotnetfaq.com/Faq/如何显示用户数量的在线用户访问者的ASP-NET-website.aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using CardCharge.Classes;

namespace CardCharge
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            Application["OnlineUsers"] = 0;
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            Application.Lock();
            Application["OnlineUsers"] = (int)Application["OnlineUsers"] + 1;
            Application.UnLock();
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            Application.Lock();
            Application["OnlineUsers"] = (int)Application["OnlineUsers"] - 1;
            Application.UnLock();
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}  

我发现了使用IHttpModule的下面的链接:

http:// blog。 sb2.fr/post/2008/12/01/HowTo-Get-Current-Online-Users-Count-and-Infos-with-ASPNET.aspx

also i found the below link that uses IHttpModule :
http://blog.sb2.fr/post/2008/12/01/HowTo-Get-Current-Online-Users-Count-and-Infos-with-ASPNET.aspx

我喜欢使用简单的global.asax为我的目的,但这两种方式都太旧了(3年前)

有在.net 4有更好的方式获得在线用户(访客数)在那里?

i prefer to use simple global.asax for my purpose , but these two ways are too old (3 years earlier)
is there any better way in .net 4 for getting online users(visitors count) out there?

也可以用于获取一些计数(例如昨天)我需要数据库!

但是可以连接sql server 2008在session_start或特殊 session_end在全局asax中?

also for getting some counts (such as yesterday) i need database !
but is it ok to connect sql server 2008 in session_start or specially session_end in global asax ?

提前感谢

推荐答案

看到的是在global.asax中使用Session_Start和Session_End。 ASP.net 4尚未更改此功能。对这种方法唯一的真正的限制是,服务器仍然会相信用户登录,直到会话结束,这不会发生,直到已经过去的会议超时配置中指定的分钟数。

The "standard" approach I have seen is to use the Session_Start and Session_End within global.asax. ASP.net 4 has not changed this functionality. The only real limitation to this approach is that the server will still believe that the user is logged on until the session ends, which does not happen until the number of minutes has passed as specified in the session timeout configuration.

有关会话超时的更多信息,请参阅此页面:
http://forums.asp.net/t/1283350.aspx

See this page for more information about session timeout: http://forums.asp.net/t/1283350.aspx

一个更强大,更新,但更多困难的方法,就是使用轮询来确保客户端始终连接到服务器。有关此主题的概述,请参阅此维基百科文章:
http://en.wikipedia。 org / wiki / Comet_(programming ))

One more robust, and newer, but much more difficult approach, is to use polling to ensure that the client is always connected to the server. See this Wikipedia article for an overview of the subject: http://en.wikipedia.org/wiki/Comet_(programming))

这篇关于asp.net的访客数(在线用户)今天 - 昨天在.net 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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