Note that there are some explanatory texts on larger screens.

plurals
  1. POBest method to remove session handled by Session Proxy pattern
    text
    copied!<p>I would like to use Proxy pattern for Session handling.</p> <p>In my session proxy class I have something like that:</p> <pre> public static class SessionProxy { private const string ThemeNameSessionName = "ThemeName"; private const string PasswordExpirationDaysSessionNam = "PasswordExpirationDays"; /// /// Gets or sets theme name. /// public static string ThemeName { get { if (Session[ThemeNameSessionName] == null) { return String.Empty; } return (string)Session[ThemeNameSessionName]; } set { Session[ThemeNameSessionName] = value; } } /// /// Gets or sets how many days to password expiration. /// public static int PasswordExpirationDays { get { return Convert.ToInt32(Session[PasswordExpirationDaysSessionNam]); } set { Session[PasswordExpirationDaysSessionNam] = value; } } } </pre> <p>so I use it in my app as:</p> <pre> SessionProxy.ThemeName = "Default"; SessionProxy.PasswordExpirationDays = 5; </pre> <p>With this piece of code I have strongly typed sessions mechanism but.. How to remove session without using string literals (like <pre>Session.Remove("ThemeName")</pre>). In case of strings I can add to my Properties:</p> <pre> set { if (String.IsNullOrEmpty(value)) { Session.Remove(ThemeNameSessionName); } else { Session[ThemeNameSessionName] = value; } } </pre> <p>but in case of other types (int, long, datetime etc.) I can't use null (I don't want to use nullable types).</p> <p>Can you advice me the best solution of this problem? The perfect one will be something like that if possible:</p> <pre> Session.Remove([some magic here]SessionProxy.ThemeName[/magic]); </pre> <p>And one thing yet, I need it in .NET 2.0 (though soulution for .NET 3.5 also will be interesting).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload