Normally, when we need a reference to the current Application state, we'd use:
HttpContext.Current.Appliction
But there are times that there's no current HttpContext (HttpContext.Current
returns null
). How can I obtain a reference to the current application instance in that case?
An example can be in Session_End
event. Although I can use Application
property inside the Session_End
event handler, but what if the handler calls a library method and the HttpApplicationState
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 static
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 HttpContext.Current.Application
approach) or do I have to choose one of the above not-so-clean methods?