Esempio n. 1
0
    /// <summary>
    ///   Ensures a specific key to be either already in the ASP.NET MVC session state or to be newly created
    /// </summary>
    /// <typeparam name = "T">The generic type to be returned</typeparam>
    /// <param name = "state">The session state.</param>
    /// <param name = "key">The session state key.</param>
    /// <returns>The session state value.</returns>
    /// <example>
    ///   <code>
    ///     public List&lt;string&gt; StringValues {
    ///     get { return this.Session.Ensure&lt;List&lt;string&gt;&gt;("StringValues"); }
    ///     set { this.ViewState.Set("StringValues", value); }
    ///     }
    ///   </code>
    /// </example>
    /// <remarks>
    ///     Contributed by Michael T, http://about.me/MichaelTran
    /// </remarks>
    public static T Ensure <T>(this HttpSessionStateBase state, string key) where T : class, new()
    {
        var value = state.Get <T>(key);

        if (value == null)
        {
            value = new T();
            state.Set(key, value);
        }

        return(value);
    }
Esempio n. 2
0
 public static void SetRoleText(this HttpSessionStateBase state, string roles)
 {
     state.Set(KEY_ROLE_TEXT, roles);
 }
Esempio n. 3
0
 public static void SetRoleIds(this HttpSessionStateBase state, int[] roleIds)
 {
     state.Set(KEY_ROLEID_LIST, roleIds);
 }
Esempio n. 4
0
 public static void SetUserDetail(this HttpSessionStateBase state, UserDetails usrDetails)
 {
     state.Set(KEY_USER_DETAIL, usrDetails);
 }
Esempio n. 5
0
 public static void SetUser(this HttpSessionStateBase state, User usr)
 {
     state.Set(KEY_USER_ID, usr.Id);
     state.Set(KEY_USER_NAME, usr.UserName);
 }