Reputation: 6066
I have about 50 application variables for each search database. In total 50 searchDB which are queried from single Search.aspx page, depending upon the query string passed in the URL it connects to Specific DB.
Eg: if Search.aspx?li=1 then connect to 1SearchDB, if Search.aspx?li=2 then Connect to 2SearchDB, .....50SearcgDB.
I am maintaining the total visitors to each searchDB depending upon the QueryString in URL and incrementing the Application Variable that are in GLOBAL.ASAX file.
In Global.asax:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["1"] = 0;
Application["2"] = 0;
.
.
Application["50"] = 0;
}
In Page_Load of Search.aspx.cs:
int LocalBody = Convert.ToInt32(Request.QueryString["li"]);
public void Page_Load(object sender, EventArgs e)
{
Label1.Text = GetHits(LocalBody).ToString();
}
private int GetHits(int LocalBody)
{
int counter=0;
switch (LocalBody)
{
case 1:
Application["1"] = (int)Application["1"] + 1;
counter=(int)Application["1"];
break;
case 2:
Application["2"] = (int)Application["2"] + 1;
counter=(int)Application["2"];
break;
.
.
case 50:
Application["50"] = (int)Application["50"] + 1;
counter=(int)Application["50"];
break; default:
break;
}
return counter;
}
Now the problem is when I am starting the application, after some time (30 to 40 mins) it restarts the counter. When I am using it then it works fine! Why does this happen?
Upvotes: 0
Views: 1143
Reputation: 606
hope it helps HydTechie
Upvotes: 0
Reputation: 66641
This is because the Application_Start
is fired and reset your counters when the application restart, and probably your application auto-restarts by your settings of your pool.
Upvotes: 0