Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hello Friends,
Have a good day all of you !!!!!

Count Menu clicks and save Number of clicks in SqlServer database 2005.
=========================================================

I have Created a WEB Application in Asp.net C#, SqlServer 2005.

In this Web Appl I have Menus Such as Home,About us, View Result, View Toppers, Contact us....etc links in menus.

When User clicks this links it must count and store in SqlServer 2005 database.

So, that I can Know how many users are viewing my web application.


Please help me brothers.


Thanks a lot
Posted

Brother you don't have to do like that.

you have Global.asax file in your web project.
C#
void Application_Start(object sender, EventArgs e)     
{
   // Code that runs on application startup.        
   Application["Visitors"] = 0;
}

void Application_End(object sender, EventArgs e) 
{
        //  Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e) 
{ 
      // Code that runs when an unhandled error occurs  
}
void Session_Start(object sender, EventArgs e) 
 {
      // Code that runs when a new session is started.
       Application.Lock();
       Application["Visitors"] = Convert.ToInt32(Application["Visitors"])+1;
       Application.UnLock();
}
void Session_End(object sender, EventArgs e) 
{} 


Whenever session_start event occurs you need to increase your visitor value by one & you can insert that value in the database.
Hope it helps
 
Share this answer
 
v2
Comments
MT_ 17-Oct-12 2:48am    
@Sushil: I think this will count unique visitor. What OP wants I think is number of pages visited.
Sushil Mate 17-Oct-12 2:55am    
@Milind: see his last line "So, that I can Know how many users are viewing my web application." so he could be want unique visitors... what he ll do by knowing the number of pages visited by visitors :)

Nevertheless its confusing one. let the OP clarify on this one
If you want to find unique visitors to your web-site, follow what Sushil has suggested above.

If you need to find total pages visited or number of pages visited, the simplest thing to do is to go for Google analytics which is free. You need to host site so that it accessible to Google Analytics.

Else, if you want to develop your own method, I would suggest you create a base page class ederived from system.page and then derive all your pages from this your own base page class.

In this custom base class, you advance total page count and user page count and/or store in database against the user.

Hope that helps. If it does, mark the answer as solution and/or upvote.

Thanks
Milind
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900