首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

老有关问题了,小弟我想写个分配和管理Session的类,有没有好的思路

2012-02-03 
老问题了,我想写个分配和管理Session的类,有没有好的思路?功能:创建Session、获取Session、判断Session是否

老问题了,我想写个分配和管理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
{


Session.Add( "popedom ",value);
}
get
{
if(isNull())
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
try
{
return long.Parse(Session[ "popedom "].ToString());
}
catch
{
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
}
}
}
/// <summary>
/// &sup1;&laquo;&Euml;&frac34;ID
/// </summary>
public long CompayID
{
set
{
Session.Add( "compayid ",value);
}
get
{
if(isNull())
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
try
{
return long.Parse(Session[ "compayid "].ToString());
}
catch
{
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
}
}
}
/// <summary>
/// &raquo;&ntilde;&Egrave;&iexcl;SESSIONID
/// </summary>
public string SessionID
{
get
{
if(isNull())
throw new Exception( "&raquo;á&raquo;°&Eacute;&ETH;&Icirc;&acute;&frac12;¨&Aacute;&cent;... ");
return Session.SessionID;
}
}
/// <summary>
/// &Aring;&ETH;&para;&Iuml;&frac12;¨&Aacute;&cent;&raquo;á&raquo;°
/// </summary>
/// <returns> bool </returns>
public bool isNull()
{
if(Session[ "cid "]==null)
return true;
else
return false;
}
/// <summary>
/// &Iuml;ú&raquo;&Ugrave;&raquo;á&raquo;°
/// </summary>
public void SessionDispose()
{
Session.Abandon();
}

[解决办法]
嗯,Session 已经过期了,现在好多web项目是基于无session的
比如petshop4.0

热点排行