老问题了,我想写个分配和管理Session的类,有没有好的思路?
功能:创建Session、获取Session、判断Session是否过期、删除Session
对Session实现统一管理,不能在页面中直接使用Session
请高手指教一下 或 给一个比较好的思路。
------解决方案--------------------try
HttpModule
------解决方案--------------------那你再弄一个外观层 不就结了?
------解决方案--------------------去年写的,这样的可以满足你的要求吗?
/// <summary>
/// SessionLib µÄժҪ˵Ã÷¡£
/// </summary>
public class SessionLib
{
private HttpSessionState Session;
public SessionLib()
{
//
// TODO: ÔÚ´Ë´¦Ìí¼Ó¹¹Ô캯ÊýÂß¼­
//³õÊÔ»¯SESSION¶ÔÏñ ³¬Ê±Ê±¼äΪ60·ÖÖÓ
Session = HttpContext.Current.Session;
Session.Timeout = 20;
}
/// <summary>
/// Óû§Ö÷¼üID
/// </summary>
public long CID
{
get
{
if(isNull())
throw new Exception( "»á»°ÉÐ佨Á¢... ");
try
{
return long.Parse(Session[ "cid "].ToString());
}
catch
{
throw new Exception( "»á»°ÉÐ佨Á¢... ");
}
}
set
{
Session.Add( "cid ",value);
}
}
/// <summary>
/// ÕʺÅ
/// </summary>
public string Account
{
set
{
this.Session.Add( "cuserid ",value);
}
get
{
if(isNull())
throw new Exception( "»á»°ÉÐ佨Á¢... ");
return this.Session[ "cuserid "].ToString();
}
}
/// <summary>
/// ÃÜÂë
/// </summary>
public string PassWord
{
set
{
Session.Add( "cpassword ",value);
}
get
{
if(isNull())
throw new Exception( "»á»°ÉÐ佨Á¢... ");
return Session[ "cpassword "].ToString();
}
}
/// <summary>
/// ½ÇÉ«
/// </summary>
public string Role
{
set
{
Session.Add( "role ",value);
}
get
{
if(isNull())
throw new Exception( "»á»°ÉÐ佨Á¢... ");
return Session[ "role "].ToString();
}
}
/// <summary>
/// ȨÏÞ
/// </summary>
public long Popedom
{
set
{