first_page

Handling Session State at Application Level

The Global class, extending System.Web.HttpApplication can be used to store static, generic functions for use throughout the application. So it may seem strange to handle anything to do with Session state in Application scope—so feel free to ignore this post and hope I take “my meds” before something really scary happens. Here’s the culprit:/// <summary> /// Returns read-only access to an instance /// of <see cref="Songhay.Data.Web.Manager"/>. /// </summary> public static Manager WebDataManager(HttpContext Context) { SessionBag userSession = new SessionBag(Context); _webData = _webDataArray[Array.IndexOf(_webKeys,userSession.Web)]; _dbName = _webData.CurrentSqlConnection.Database; _dbServer = _webData.CurrentSqlConnection.DataSource; _dbTimeout = _webData.CurrentSqlConnection.ConnectionTimeout; return _webData; }

Today, at about 2:15 this afternoon, this seems like a great idea. Who knows what danger and adventure 2:30 holds? In the meantime, notice that HttpContext is passed to this static member. This context is used to “new up” something I call a “Session Bag,” which is a strongly-typed definition of all Session variables to be used in the application. (Also, by the way, there is a “Request bag” struct that performs the same function. These definitions are designed to make the application easier to maintain but time-consuming to build—most IT managers dislike the time-consuming part of this deal.)

To new up a Session bag from application scope with page-level context appears to accomplish what I am looking for… Right now, it’s about 2:25… Later.

rasx()