i want to know the number hits customers are visting
-
i want to know the number of hits my application is being hited.i am using asp.net2.0 with c#.
then write some code to increment a counter every time a page loads.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
then write some code to increment a counter every time a page loads.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
I think the following code will help you. In your application folder create a text file named "Counter.txt" and put 0 in that file. Write the following in the code behind page. protected void Page_Load(object sender, EventArgs e) { myLabel .Text = counter(); } public string counter() { StreamReader re = File.OpenText(Server.MapPath("Counter.txt")); string input = null; string mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); int myInt = int.Parse(mycounter); myInt = myInt + 1; TextWriter tw = new StreamWriter(Server.MapPath("Counter.txt")); tw.WriteLine(Convert.ToString(myInt)); tw.Close(); re = File.OpenText(Server.MapPath("Counter.txt")); input = null; mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); return mycounter; }
-
I think the following code will help you. In your application folder create a text file named "Counter.txt" and put 0 in that file. Write the following in the code behind page. protected void Page_Load(object sender, EventArgs e) { myLabel .Text = counter(); } public string counter() { StreamReader re = File.OpenText(Server.MapPath("Counter.txt")); string input = null; string mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); int myInt = int.Parse(mycounter); myInt = myInt + 1; TextWriter tw = new StreamWriter(Server.MapPath("Counter.txt")); tw.WriteLine(Convert.ToString(myInt)); tw.Close(); re = File.OpenText(Server.MapPath("Counter.txt")); input = null; mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); return mycounter; }
Well, you should answer the OP, not me. This code also has some big issues. First of all, it is prone to crashing. Never use int.Parse, always use int.TryParse. It's also way too many lines, I could write it in a lot less. Finally, won't it crash if the file does not exist ?
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Well, you should answer the OP, not me. This code also has some big issues. First of all, it is prone to crashing. Never use int.Parse, always use int.TryParse. It's also way too many lines, I could write it in a lot less. Finally, won't it crash if the file does not exist ?
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
then what is the best solution
-
then what is the best solution
A text file is an OK solution, if the website doesn't have a database behind it 1 - check if the file exists before you open it, if not create it 2 - use int.TryParse so that if the file is corrupt, it resets rather than blow up the site
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
A text file is an OK solution, if the website doesn't have a database behind it 1 - check if the file exists before you open it, if not create it 2 - use int.TryParse so that if the file is corrupt, it resets rather than blow up the site
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Thank you
-
I think the following code will help you. In your application folder create a text file named "Counter.txt" and put 0 in that file. Write the following in the code behind page. protected void Page_Load(object sender, EventArgs e) { myLabel .Text = counter(); } public string counter() { StreamReader re = File.OpenText(Server.MapPath("Counter.txt")); string input = null; string mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); int myInt = int.Parse(mycounter); myInt = myInt + 1; TextWriter tw = new StreamWriter(Server.MapPath("Counter.txt")); tw.WriteLine(Convert.ToString(myInt)); tw.Close(); re = File.OpenText(Server.MapPath("Counter.txt")); input = null; mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); return mycounter; }
You need some kind of locking. This is not thread safe.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
i want to know the number of hits my application is being hited.i am using asp.net2.0 with c#.
Best method would be using services like Google analytics[^]. If you want to implement your own tracker, better use database to keep the information, you don't need to worry about thread safety. But keep it in mind, if the application is getting good hits, your database will become huge in size.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
You need some kind of locking. This is not thread safe.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
I was trying not to get too confusing :-)
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
I was trying not to get too confusing :-)
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
:)
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
then write some code to increment a counter every time a page loads.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
i did not get.could u send me the sample code.i just want to display the number of hits in asmal table or in any graphical image
I'm sorry, someone gave code, I corrected it, if you can't work it out, then I don't know what else to say.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )