| | |
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 activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






