1.You should have different counters for each page, and store these counters in
Application
cache to be at the web application level;
2.In the
Global.asax.cs
init your used counter for each page like in the next example:
void Application_Start(object sender, EventArgs e)
{
Application["Page1Counter"] = 0;
Application["Page2Counter"] = 0;
}
2.The logic for incrementing the counters
for each page
should be in the
Page_Load
event handler like in the next example:
protected void Page1_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int counter = (int)Application["Page1Counter"];
counter++;
Application["Page1Counter"] = counter;
}
}
3.Example for your new question regarding only one page and multiple users:
protected void Page1_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string userID = User.Identity.Name;
string key = string.Format("Page1CounterForUser{0}", userID);
int counter = (int)Application[key];
counter++;
Application[key] = counter;
}
}