Accessing HttpApplicationState where there is no current HttpContext available

GoMike

New Member
Normally, when we need a reference to the current Application state, we'd use:\[code\]HttpContext.Current.Appliction\[/code\]But there are times that there's no current HttpContext (\[code\]HttpContext.Current\[/code\] returns \[code\]null\[/code\]). How can I obtain a reference to the current application instance in that case?An example can be in \[code\]Session_End\[/code\] event. Although I can use \[code\]Application\[/code\] property inside the \[code\]Session_End\[/code\] event handler, but what if the handler calls a library method and the \[code\]HttpApplicationState\[/code\] object is required in the library code? I don't like to pass an "application" parameter around...I also don't like keeping it in a \[code\]static\[/code\] field (like Singleton pattern) and I'm looking for a way to directly get it from context.Is there any way to access the instance directly (similar to \[code\]HttpContext.Current.Application\[/code\] approach) or do I have to choose one of the above not-so-clean methods?
 
Back
Top