日期:2014-05-19  浏览次数:20449 次

老问题了,我想写个分配和管理Session的类,有没有好的思路?
功能:创建Session、获取Session、判断Session是否过期、删除Session
对Session实现统一管理,不能在页面中直接使用Session
请高手指教一下   或   给一个比较好的思路。

------解决方案--------------------
try
HttpModule

------解决方案--------------------
那你再弄一个外观层 不就结了?
------解决方案--------------------
去年写的,这样的可以满足你的要求吗?
/// <summary>
/// SessionLib &micro;&Auml;&Otilde;&ordf;&Ograve;&ordf;&Euml;&micro;&Atilde;÷&iexcl;&pound;
/// </summary>
public class SessionLib
{
private HttpSessionState Session;
public SessionLib()
{
//
// TODO: &Ocirc;&Uacute;&acute;&Euml;&acute;&brvbar;&Igrave;í&frac14;&Oacute;&sup1;&sup1;&Ocirc;ì&ordm;&macr;&Ecirc;&yacute;&Acirc;&szlig;&frac14;&shy;
//&sup3;&otilde;&Ecirc;&Ocirc;&raquo;&macr;SESSION&para;&Ocirc;&Iuml;&ntilde; &sup3;&not;&Ecirc;±&Ecirc;±&frac14;&auml;&Icirc;&ordf;60·&Ouml;&Ouml;&Oacute;
Session = HttpContext.Current.Session;
Session.Timeout = 20;
}
/// <summary>
/// &Oacute;&Atilde;&raquo;§&Ouml;÷&frac14;üID
/// </summary>
public long CID
{
get
{
if(isNull())
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
try
{
return long.Parse(Session[ "cid "].ToString());
}
catch
{
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
}
}
set
{
Session.Add( "cid ",value);
}
}
/// <summary>
/// &Otilde;&Ecirc;&ordm;&Aring;
/// </summary>
public string Account
{
set
{
this.Session.Add( "cuserid ",value);
}
get
{
if(isNull())
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
return this.Session[ "cuserid "].ToString();
}
}
/// <summary>
/// &Atilde;&Uuml;&Acirc;&euml;
/// </summary>
public string PassWord
{
set
{
Session.Add( "cpassword ",value);
}
get
{
if(isNull())
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
return Session[ "cpassword "].ToString();
}
}
/// <summary>
/// &frac12;&Ccedil;&Eacute;&laquo;
/// </summary>
public string Role
{
set
{
Session.Add( "role ",value);
}
get
{
if(isNull())
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
return Session[ "role "].ToString();
}
}
/// <summary>
/// &Egrave;¨&Iuml;&THORN;
/// </summary>
public long Popedom
{
set
{