| | |
Implementing a visitor counter
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 45
Reputation:
Solved Threads: 0
I am a newbie and developing a website using ASP .Net 2.0 with C# 2005. I would like to add a facility to count the no. of visitors to my website. I have collected the basic informations to add this feature using Global.asax. I have made modifications to Web.config by adding the line "<sessionState mode="InProc" cookieless="false" timeout="60" />" under system.web section.
I am using a table to keep the count of visitors. But I don't know how to complete the task. My default Global.asax file came with different sections Application_Start, Application_End, Application_Error, Session_Start and Session_End. I have tried to extract the current value of the counter in the Application_Start section and store in a global variable. I would increment the counter in Session_Start and write the modified value to the table in Application_End.
I have tried to use public subroutines/functions. But where should I place those subroutines? I tried to add the subroutines in the Global.asax itself. But now I am getting errors, as I can not add reference to Data.SqlClient in Global.asax and I need references to SqlConnection, SqlCommand, SqlDataReader etc. to implement the features. Do I have to add Class files for each subroutines? Please guide me.
I would also like to implement tracking feature to my website and store the IP address, browser used, date and time of visit, screen resolution etc of my websites visitors. How can I do it?
Waiting for suggestions.
Lalit Kumar Barik
I am using a table to keep the count of visitors. But I don't know how to complete the task. My default Global.asax file came with different sections Application_Start, Application_End, Application_Error, Session_Start and Session_End. I have tried to extract the current value of the counter in the Application_Start section and store in a global variable. I would increment the counter in Session_Start and write the modified value to the table in Application_End.
I have tried to use public subroutines/functions. But where should I place those subroutines? I tried to add the subroutines in the Global.asax itself. But now I am getting errors, as I can not add reference to Data.SqlClient in Global.asax and I need references to SqlConnection, SqlCommand, SqlDataReader etc. to implement the features. Do I have to add Class files for each subroutines? Please guide me.
I would also like to implement tracking feature to my website and store the IP address, browser used, date and time of visit, screen resolution etc of my websites visitors. How can I do it?
Waiting for suggestions.
Lalit Kumar Barik
hi,
check this code.assign this in your global.asx file
check this code.assign this in your global.asx file
ASP.NET Syntax (Toggle Plain Text)
Sub Application_OnStart 'initialize variable Application("visitors_online") = 0 End Sub Sub Application_OnEnd End Sub Sub Session_OnStart Session.Timeout = 20 '20 minute timeout Application.Lock Application("visitors_online") = Application("visitors_online") + 1 Application.Unlock End Sub Sub Session_OnEnd Application.Lock Application("visitors_online") = Application("visitors_online") - 1 Application.Unlock End Sub On line users: <%=Application("visitors_online")%>
If u r query is achieved,mark the thread as solved
Live and Let Live
Live and Let Live
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
What the previous post gave you was a way to know how many people are online at any given moment, however, it is very unstable as you are not guaranteed to trigger Session_OnEnd, and if you look into it, it's normally not fired for beginners.
I would suggest, just like he stated above, put in the global.asax file a Session_OnStart method. In this method, you can tap your database and insert a row. Look up how to retrieve the IP info, and you can also retrieve everything about the user's browser and certain computer information as well.
However, I would suggest not using a database for this for every visitor. And if you decide to, use Asynchronous calls. You don't want your visitor to wait even 1 second before the page starts to load.
I would suggest writing this to a file, or XML. Then set up a trigger so that every hour, or 6 hours, you read through the XML and send the data to the database. Thus your visitors do not wait for anything. You can also set up the file IO writing to be Asynchronous as well. This is more of an advanced step, but will save you lots of trouble in the future.
I would suggest, just like he stated above, put in the global.asax file a Session_OnStart method. In this method, you can tap your database and insert a row. Look up how to retrieve the IP info, and you can also retrieve everything about the user's browser and certain computer information as well.
However, I would suggest not using a database for this for every visitor. And if you decide to, use Asynchronous calls. You don't want your visitor to wait even 1 second before the page starts to load.
I would suggest writing this to a file, or XML. Then set up a trigger so that every hour, or 6 hours, you read through the XML and send the data to the database. Thus your visitors do not wait for anything. You can also set up the file IO writing to be Asynchronous as well. This is more of an advanced step, but will save you lots of trouble in the future.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
I answer questions.
I answer quickly.
I answer.
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: data grid view
- Next Thread: TreeView Problem
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax appliances asp asp.net beginner box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox class compatible confirmationcodegeneration content contenttype control countryselector courier css dataaccesslayer database datagrid datagridview datalist deadlock deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv forms gridview gudi homeedition iis javascript jquery list listbox menu mssql multistepregistration nameisnotdeclared news novell objects opera order problem radio ratings redirect registration relationaldatabases reportemail rotatepage search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview validatedate validation vb.net videos virtualdirectory vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming wizard xml xsl






