-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSessionHelper.cs
More file actions
48 lines (40 loc) · 853 Bytes
/
SessionHelper.cs
File metadata and controls
48 lines (40 loc) · 853 Bytes
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
public class SessionHelper<T>
{
private string Key;
public SessionHelper()
{
this.Key = typeof(T).Name;
}
public bool IsNotNull()
{
return this.Get() != null;
}
public bool IsNull()
{
return !this.IsNotNull();
}
public void Save(object value)
{
HttpContext.Current.Session[Key] = value;
}
public T Get()
{
return (T)HttpContext.Current.Session[Key];
}
public void Destroy()
{
HttpContext.Current.Session.Remove(Key);
}
public static void Destroy(string key)
{
HttpContext.Current.Session.Remove(key);
}
}
/*
///how to use
public ActionResult Test() {
SessionHelper<PostRequestModel> sh = new SessionHelper<PostRequestModel>();
if (sh.IsNull()) return HttpNotFound();
return View();
}
*/