REA_ANDREW
asked on
Global.asax file
Hi,
I am starting to use the global.asax file, as I have never touched on it before. I successfuly increment an application value when a session starts, but when a session ends, I subtract one from this value. The Session End process is not firing, and the value just keeps increasing. Please could some one advise.
Thanks in advance
Andrew
P.s. My Code
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
Application["NoUsers"] = 0;
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
Application["NoUsers"] = Convert.ToInt32(Applicatio n["NoUsers "]) - 1;
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Application["NoUsers"] = Convert.ToInt32(Applicatio n["NoUsers "]) - 1;
}
void Session_Start(object sender, EventArgs e)
{
Application["NoUsers"] = Convert.ToInt32(Applicatio n["NoUsers "])+1;
Response.Write(Application ["NoUsers" ].ToString ());
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
Application["NoUsers"] = Convert.ToInt32(Applicatio n["NoUsers "]) - 1;
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
I am starting to use the global.asax file, as I have never touched on it before. I successfuly increment an application value when a session starts, but when a session ends, I subtract one from this value. The Session End process is not firing, and the value just keeps increasing. Please could some one advise.
Thanks in advance
Andrew
P.s. My Code
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
Application["NoUsers"] = 0;
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
Application["NoUsers"] = Convert.ToInt32(Applicatio
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Application["NoUsers"] = Convert.ToInt32(Applicatio
}
void Session_Start(object sender, EventArgs e)
{
Application["NoUsers"] = Convert.ToInt32(Applicatio
Response.Write(Application
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
Application["NoUsers"] = Convert.ToInt32(Applicatio
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
Are you actually waiting long enough for the sessions to expire when testing ?
ASKER
Does the session automatically end when a browser window is shut?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Right, thanks for that, much appreciated