1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
using System.Web;
namespace www.drescher.hackel.de.SessionApp
{
/// <summary>
/// Enum zum Verwalten der SessionKeys
/// </summary>
public enum SessionKey
{
Benutzer
}
/// <summary>
/// Statische Klasse zum Verwalten der Session
/// </summary>
public static class AppSession
{
/// <summary>
/// Gibt die Session mit den übergebenen SessionKey als Key zurück
/// </summary>
/// <param name="name">SessionKey</param>
/// <returns>object</returns>
public static object Get(SessionKey name)
{
return HttpContext.Current.Session[name.ToString()];
}
/// <summary>
/// Setzt die Session mit dem übergebenen SessionKey als Key
/// </summary>
/// <param name="name">SessionKey</param>
/// <param name="value">object</param>
public static void Set(SessionKey name, object value)
{
HttpContext.Current.Session[name.ToString()] = value;
}
/// <summary>
/// Entfernt die Session entsprechend dem übergebenen SessionKey
/// </summary>
/// <param name="name">SessionKey</param>
public static void Remove(SessionKey name)
{
HttpContext.Current.Session.Remove(name.ToString());
}
}
/// <summary>
/// Statische Klasse für Erweiterungsmethoden
/// </summary>
public static class ExtendSession
{
#region Extends System.Web.SessionState.HttpSessionState
/// <summary>
/// Erweitert System.Web.SessionState.HttpSessionState, um den Wert der Session entsprechend des übergebenen SessionKey zu ermitteln
/// </summary>
/// <param name="session">System.Web.SessionState.HttpSessionState</param>
/// <param name="name">SessionKey</param>
/// <returns>object</returns>
public static object Get(this System.Web.SessionState.HttpSessionState session,
SessionKey name)
{
return AppSession.Get(name);
}
/// <summary>
/// Erweitert System.Web.SessionState.HttpSessionState, um den Wert der Session entsprechend des übergebenen SessionKey zu setzen
/// </summary>
/// <param name="session">System.Web.SessionState.HttpSessionState</param>
/// <param name="name">SessionKey</param>
/// <param name="value">object</param>
public static void Set(this System.Web.SessionState.HttpSessionState session,
SessionKey name, object value)
{
AppSession.Set(name, value);
}
/// <summary>
/// Erweitert System.Web.SessionState.HttpSessionState, um den Wert der Session entsprechend des übergebenen SessionKey zu ermitteln
/// Überschreibt dabei die bestehende Add-Methode
/// </summary>
/// <param name="session">System.Web.SessionState.HttpSessionState</param>
/// <param name="name">SessionKey</param>
/// <returns>object</returns>
public static void Add(this System.Web.SessionState.HttpSessionState session,
SessionKey name, object value)
{
AppSession.Set(name, value);
}
/// <summary>
/// Erweitert System.Web.SessionState.HttpSessionState, zum Entfernen der Session entsprechend dem übergebenen SessionKey
/// </summary>
/// <param name="name">SessionKey</param>
public static void Remove(this System.Web.SessionState.HttpSessionState session,
SessionKey name)
{
AppSession.Remove(name);
}
#endregion
#region Extends SessionKey
/// <summary>
/// Erweiterterung des Enums SessionKey zum Abrufen des Sessionswertes entsprechend des selektierten SessionKeys
/// </summary>
/// <param name="name">SessionKey</param>
/// <returns>object</returns>
public static object Get(this SessionKey name)
{
return AppSession.Get(name);
}
/// <summary>
/// Erweiterterung des Enums SessionKey zum Setzen des Sessionswertes entsprechend des selektierten SessionKeys
/// </summary>
/// <param name="name">SessionKey</param>
/// <param name="value">object</param>
public static void Set(this SessionKey name, object value)
{
AppSession.Set(name, value);
}
/// <summary>
/// Erweiterterung des Enums SessionKey zum Entfernen der Session entsprechend dem übergebenen SessionKey
/// </summary>
/// <param name="name">SessionKey</param>
public static void Remove(this SessionKey name)
{
AppSession.Remove(name);
}
#endregion
}
}
|