In my ASP.NET application using InProc sessions, Session_End calls a static method in another object to do session-specific clean up. This clean up uses a shared database connection that I am storing in application state.
The problem is that I cannot see how to access the application state without passing it (or rather the database connection) as a parameter to the clean up method. Since I am not in a request I have no current HttpContext, and I cannot find any other static method to access the state.
Am I missing something?
UPDATE: It appears that my question needs further clarification, so let me try the following code sample. What I want to be able to do is:
// in Global.asax
void Session_End(object sender, EventArgs e)
{
NeedsCleanup nc = Session["NeedsCleanup"] as NeedsCleanup;
nc.CleanUp();
}
But the problem is that the CleanUp
method in turn needs information that is stored in application state. I am already doing the following, but it is exactly what I was hoping to avoid; this is what I meant by "...without passing it... as a parameter to the clean up method" above.
// in Global.asax
void Session_End(object sender, EventArgs e)
{
NeedsCleanup nc = Session["NeedsCleanup"] as NeedsCleanup;
nc.CleanUp(this.Application);
}
I just do not like the idea that Global.asax
has to know where the NeedsCleanup
object gets its information. That sort of thing that makes more sense as self-contained within the class.