using HttpContext = System.Web.HttpContext;
using System.Threading;
namespace CRMWeb.eDAS.Util
{
public sealed class EDasSession<TClass> where TClass : class ,new()
{
#region member
private readonly ReaderWriterLockSlim _lockSlim = new ReaderWriterLockSlim();
#endregion
#region methods
public TClass Current
{
get
{
return HttpContext.Current.Session[Key] == null
? null
: (TClass)HttpContext.Current.Session[Key];
}
}
public TClass Set(TClass value)
{
var sessionObj = HttpContext.Current.Session[Key];
if (sessionObj == null)
{
_lockSlim.EnterWriteLock();
if (sessionObj == null)
{
HttpContext.Current.Session[Key] = value;
}
_lockSlim.ExitWriteLock();
}
else
{
_lockSlim.EnterWriteLock();
HttpContext.Current.Session[Key] = value;
_lockSlim.ExitWriteLock();
}
return (TClass)sessionObj;
}
public void Remove()
{
HttpContext.Current.Session.Remove(Key);
}
#endregion
#region Private
private string Key
{
get { return typeof(EDasSession<TClass>).FullName; }
}
#endregion
}
}
You can create a Website context like this :
using CRMWeb.eDAS.Entities.SessionEntity;
namespace CRMWeb.eDAS.Util
{
public sealed class EdasContext
{
public static EDasSession<SessionBranchInfo> BranchLoginSession;
public static EDasSession<SessionUserInfo> SalesPersonSession;
public static EDasSession<SessionCustomerQueueInfo> CustomerQueueSession;
public static EDasSession<SessionCustomerPersonalDetails> CustomerDetailsSession;
public static EDasSession<SessionPaymentInfo> CurrentPaymentSession;
public static EDasSession<SessionCheckoutInfo> CheckoutInfo;
public static EDasSession<SessionInfoVoucherDetails> VoucherDetailsSession;
public static EDasSession<SessionServiceInfo> CurrentServiceSession;
public static EDasSession<SessionTicketInfo> TicketInfoSession;
public static EDasSession<SessionShoppingCart> ShoppingCartSession;
static EdasContext()
{
if(BranchLoginSession == null) BranchLoginSession = new EDasSession<SessionBranchInfo>();
if(SalesPersonSession == null) SalesPersonSession = new EDasSession<SessionUserInfo>();
if(CustomerQueueSession == null) CustomerQueueSession = new EDasSession<SessionCustomerQueueInfo>();
if(CustomerDetailsSession == null) CustomerDetailsSession = new EDasSession<SessionCustomerPersonalDetails>();
if(CurrentPaymentSession == null) CurrentPaymentSession = new EDasSession<SessionPaymentInfo>();
if(CheckoutInfo == null) CheckoutInfo = new EDasSession<SessionCheckoutInfo>();
if(VoucherDetailsSession == null) VoucherDetailsSession = new EDasSession<SessionInfoVoucherDetails>();
if(CurrentServiceSession == null) CurrentServiceSession = new EDasSession<SessionServiceInfo>();
if(TicketInfoSession == null) TicketInfoSession = new EDasSession<SessionTicketInfo>();
if(ShoppingCartSession == null) ShoppingCartSession = new EDasSession<SessionShoppingCart>();
}
public static void ClearAll()
{
BranchLoginSession.Remove();
SalesPersonSession.Remove();
TicketInfoSession.Remove();
ClearCustomerSession();
}
public static void ClearCustomerSession()
{
CustomerQueueSession.Remove();
CustomerDetailsSession.Remove();
CurrentPaymentSession.Remove();
CheckoutInfo.Remove();
VoucherDetailsSession.Remove();
CurrentServiceSession.Remove();
ShoppingCartSession.Remove();
}
}
}
分享到:
相关推荐
在asp.net中使用session常见问题集锦
ASP.NET的 Session 详解
在后台应用程序中设置:Session.Timeout = 1; 注意:1、此方法可以设置在一个公共的页面中,然后直接调用即可。 2、时间是以分钟为单位的 方法二: 在Web.config中设置: 在<system></system>中写入...
使用session实现的简单购物车,没有使用数据库,便于初学者理解session功能。
.net MVC使用Session验证用户登录,直接输入URL的页面地址跳转到登陆页 ,必须经过用户登录授权才可以。例如输入:http://localhost:14613/Home/index 由于没有登录将直接跳转到http://localhost:14613/Account/Login...
一个基于 ASP.Net的进行Session 处理的高级技巧程序例子代码。
【ASP.NET编程知识】ASP.NET通过分布式Session提升性能.docx
比较学习ASP.net中的Session、ViewState、Application、Cookies
【ASP.NET编程知识】asp.net中穿透Session 0 隔离(二).docx
ASP.NET 2010 用session开发的聊天室实例
[ASP.NET] Session 详解
ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP.NET入门经典ASP...
关闭页面时清空Session (ASP.net ) (已实现)
本资源是用session实现的一个购物车,是用链表和session实现的购物车,希望对您有所帮助
ASP.NET中简单的Session、Application、Cookie的小例子
asp.net简单会话(session)应用,可以对会话机制有个大概的了解
ASP.NET 中 Session 实现原理浅析 如 session的说明 使用等等
asp.net 应用程序,通过web.config 应用程序发布到IIS上,实现不同应用程序之间session 共享
ASP.NET 参考手册 在 W3School,我们提供完整的 ASP.NET 参考手册,其中包括内建对象和组件,以及它们的属性和方法。 ASP.NET 实例 ASP.NET 实例 一系列的 ASP.NET 实例。 内容目录 ASP.NET 简介 本章解释 ASP.NET...
asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程asp.net教程...