计算访客人数 [英] Count the no of Visitors

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

问题描述

我已将简历存储在数据库中,并且通过创建linkbutton从asp.net网页中检索了它...我可以查看,下载我存储在数据库中的简历.我的烦恼是当我查看一个简历示例时(本地简历)那么应该算出本地简历的访客人数.如果我再次认为访客的简历人数应该是2 ...我该如何在asp.net上做到这一点?

I have stored resumes in my database and i have retrive it from asp.net web page by creating linkbutton...i can view ,download the resumes which i stored in my database.My issuse is when i view one resume example (domnic resume)then no of visitor for domnic resume should be count .if again i view that resume no of visitor should be 2...how can i do that in asp.net?

推荐答案

有很多方法可以做到这一点,每种方法都有其独特之处.这是一种快速而又肮脏的方法,唯一要记住的是Session_OnEnd可能有点不稳定.

There are a ton of ways to do this, each have their quirks. Here is a quick and dirty way to do it, the only thing to remember is that the Session_OnEnd can be a bit flaky.

public void Application_OnStart(Object sender, EventArgs e)
  {
    Hashtable ht = (Hashtable)Application["SESSION_LIST"];
    if(ht == null)
    {
      ht = new Hashtable();
      lock(Application)
      {
        Application["SESSION_LIST"] = ht;
        Application["TOTAL_SESSIONS"] = 0;
      }
    }
  }

  public void Session_OnStart(Object sender, EventArgs e)
  {

    Hashtable ht = (Hashtable)Application["SESSION_LIST"];
    if(ht.ContainsKey(Session.SessionID) == false)
    {
      ht.Add(Session.SessionID, Session);
    }

    lock(Application)
    {
      int i = (int)Application["TOTAL_SESSIONS"];
      i++;
      Application["TOTAL_SESSIONS"] = i;
    }
  }

  public void Session_OnEnd(Object sender, EventArgs e)
  {
    Session.Clear();
    Hashtable ht = (Hashtable)Application["SESSION_LIST"];
    ht.Remove(Session.SessionID);

    lock(Application)
    {
      int i = (int)Application["TOTAL_SESSIONS"];
      i--;
      Application["TOTAL_SESSIONS"] = i;
    }

  }

这是另一种方式...

Here's another way...

Membership.GetNumberOfUsersOnline();

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

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