| sed and can determine if you should be using a different key.
However, we are still not ensuring consistency of data type.
A Much Better Way - Using a Facade Only access the HttpSessionState from within one single static class in your application - the facade. There must be no direct access to the Session property from within code on pages or controls, and no direct access to HttpContext.Current.Session other than from within the facade
All session variables will be exposed as properties of the facade class.
This has the same advantages as using a single class for all the session keys, plus the following advantages:
Strong typing of what gets put into session variables. No need for casting in code where session variables are used. All the benefits of property setters to validate what gets put into session variables (more than just type). All the benefits of property getters when accessing session variables. For example, initialising a variable the first time it is accessed. An Example Session Facade Class Here is an example class to implement the Session facade for an application called MyApplication.
Collapse /// <summary> /// MyApplicationSession provides a facade to the ASP.NET Session object. /// All access to Session variables must be through this class. /// </summary> public static class MyApplicationSession { # region Private Constants //--------------------------------------------------------------------- private const string userAuthorisation = "UserAuthorisation"; private const string teamManagementState = 上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] 下一页 |