ASP.NET - how many people visited my page online

Asked By kiruba .e on 13-Feb-12 02:24 AM
Hi,


I created a page and hosted in online.  Just i want to know, how many people visited or seen my page in online.  How to get the count of no of users on my page.   How to do this in asp.net

Pls help

regards,
kiruba.e
dipa ahuja replied to kiruba .e on 13-Feb-12 02:40 AM
► Add a Global.asax file in your website >> Add New Item >>Global Application Class and write this code in it.
 
 public static int count = 0;
 
void Application_Start(object sender, EventArgs e)
  {
   
Application["myCount"] = count;
 }

 
void Session_Start(object sender, EventArgs e)
  {
   count =
Convert.ToInt32(Application["myCount"]);
   
Application["myCount"] = count + 1;
 }
 
Now every time when visitor open your site the variable count will be increased by one.
 
► To Get the total at you home page you can write it as:
 
int a;
a = Convert.ToInt32(Application["myCount"]);
 
 
kiruba .e replied to dipa ahuja on 13-Feb-12 02:43 AM
if i hosted in online, overall count can i find? different user will see my site from diff.system. 
dipa ahuja replied to kiruba .e on 13-Feb-12 02:57 AM
Yes this will increase the count whenever new user from any other machine visit your site
Web Star replied to kiruba .e on 13-Feb-12 03:34 AM
Better is you can use Imports System.IO and write the counter value in xml file than if your application end than also preserved previous hit count value as permanent and one more thing you can specify the page specific hit count using this method so put the code to get hit couter from that xml file in page load of that page and show it in label control simply
 
  
PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load


IfNot Page.IsPostBack Then
Dim nCount As Int32 = 0
nCount = GetCounterValue()
lblTest.Text = nCount.ToString()

EndIf
EndSub


PrivateFunction GetCounterValue() As Int32


Dim ctrFile As StreamReader
Dim ctrFileW As FileStream
Dim sw As StreamWriter
Dim strPath AsString = Server.MapPath("indexcount.txt")
Dim strCounterContents AsString
Dim nCounter As Int32
 
If (File.Exists(strPath)) Then
ctrFile = File.OpenText(strPath)
strCounterContents = ctrFile.ReadLine().ToString()
ctrFile.Close()
nCounter = Convert.ToInt32(strCounterContents)
Else
nCounter = 0
EndIf
nCounter += 1
ctrFileW = New FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write)
sw = New StreamWriter(ctrFileW)
sw.WriteLine(Convert.ToString(nCounter))
sw.Close()
ctrFileW.Close()
Return nCounter
EndFunction


kalpana aparnathi replied to kiruba .e on 13-Feb-12 04:01 AM
hi,

Use http://en.wikipedia.org/wiki/Google_Analytics or http://www.iis.net/community/default.aspx?tabid=34&g=6&i=1864 on your web server or Use a tool like Log Parser or a stat application to parse the IIS logs.

Regards,
Sandeep Mittal replied to kiruba .e on 13-Feb-12 04:25 AM
Use Google Analytics. You can open google analytics account for free.
http://www.google.com/analytics/
It has lot of various features and reports.
[)ia6l0 iii replied to kiruba .e on 13-Feb-12 09:10 PM
The only foolproof way to find unique visitors to your site/page - without much coding - is to use the services of third-party like http://www.omniture.com/en/products/analytics/sitecatalyst. Believe me, I have almost tried all ways suggested above - and none are fool-proof. 

Simplest way to integrate to their services is to drop a script that they give. 

They have a pretty good support team and can give you code samples on the reporting aspects as well. And note that with their web analytics package, you get more than the unique visitors. 

Hope this helps.