-
Notifications
You must be signed in to change notification settings - Fork 1
/
SessionManagement.cs
40 lines (35 loc) · 1.24 KB
/
SessionManagement.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Logic.CS.BusinessLogic.Adthena
{
public static class SessionManagement
{
public static T GetSession<T>(string key)
{
object sessionObject = HttpContext.Current.Session[key];
if (sessionObject == null)
{
return default(T);
}
return (T)HttpContext.Current.Session[key];
}
public static void SaveOrUpdateSession<T>(string key, T entity)
{
object sessionObject = HttpContext.Current.Session[key];
if (sessionObject != null)
{
DeleteSession(key);
}
HttpContext.Current.Session[key] = entity;
}
public static void DeleteSession(string key)
{
HttpContext.Current.Session.Remove(key);
}
}
//Usage
// SessionManagement.SaveOrUpdateSession(StringConstant.INFRINGEMENTGRID_SESSION, model); e.g model is List<InfringementGrid>
//var infringementGrid = SessionManagement.GetSession<List<InfringementGrid>>(StringConstant.INFRINGEMENTGRID_SESSION);
}