Wesite visited counter.
in my website how to count websute visited count when home page load.please give me any sample code.i'm using asp.net.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lalit MRank #1,186 · 1.5K reputationPosted Nov 25, 2009, 1:43 AM EST
private int GetCounterValue()
{
StreamReader ctrFile;
FileStream ctrFileW;
StreamWriter sw;
string strPath = Server.MapPath( "myappcounter.txt");
string strCounterContents;
int nCounter;
if (File.Exists(strPath))
{
ctrFile = File.OpenText(strPath);
strCounterContents = ctrFile.ReadLine().ToString();
ctrFile.Close();
nCounter = Convert.ToInt32(strCounterContents);
}
else
nCounter = 0;
nCounter++;
ctrFileW = new FileStream(strPath, FileMode.OpenOrCreate,FileAccess.Write);
sw = new StreamWriter(ctrFileW);
sw.WriteLine(Convert.ToString(nCounter));
sw.Close();
ctrFileW.Close();
return nCounter;
}
Lalit MRank #1,186 · 1.5K reputationPosted Nov 24, 2009, 10:42 PM EST
--------------
public class SessionPurger : IHttpModule { private static Timer timer; private const int interval = 1000 * 60 * 10; // ------------------------------------------------------ public void Init(HttpApplication application) { // Wire-up application events if (timer == null) timer = new Timer(new TimerCallback(ScheduledWorkCallback), application.Context, 0, interval); } // ------------------------------------------------------ private void ScheduledWorkCallback (object sender) { HttpContext ctx = (HttpContext) sender; DataProvider.Instance (ctx).PurgeExpiredSessions (); } // ------------------------------------------------------- public void Dispose() { timer = null; } }