Count the no of Visitors
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 as开发者_开发知识库p.net?
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();
You can keep track of no of views displayed by keeping the count in the database or a persistent storage of your choice. Whenever a particular resume view is requested, update the view count for that resume. You may disclose some elements of the design you have done to get more specific answers.
If you just want to see this count as a developer/admin, and you have interest in collecting stats site-wide, you may also look into using Google Analytics.
精彩评论