Page Hit counter asp.net,c#
March 16, 2010 at 9:53 am 1 comment
.cs page
protected void Page_Load(object sender, EventArgs e)
{
this.countMe();
DataSet tmpDs = new DataSet();
tmpDs.ReadXml(Server.MapPath(“~/counter.xml”));
lblCounter.Text = tmpDs.Tables[0].Rows[0]["hits"].ToString();
}
private void countMe()
{
DataSet tmpDs = new DataSet();
tmpDs.ReadXml(Server.MapPath(“~/counter.xml”));
int hits = Int32.Parse(tmpDs.Tables[0].Rows[0]["hits"].ToString());
hits += 1;
tmpDs.Tables[0].Rows[0]["hits"] = hits.ToString();
tmpDs.WriteXml(Server.MapPath(“~/counter.xml”));
}
.xml page
<?xml version=”1.0″ standalone=”yes”?>
<counter>
<count>
<hits>6</hits>
</count>
</counter>
Entry filed under: asp.net, C#. Tags: asp.net page hit, easy hit counter c#, hit counter, page hit.

1.
Ali Umair | September 19, 2011 at 7:52 am
Thanks for the solution but the counter is not updating itself.
might be some problem with the XML file, can you help me?