欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net 簡單單點登錄技術分析

 更新時間:2011年02月14日 21:58:05   作者:  
單點登錄,又叫SSO(Single Sign On)。在一些cms或者OA中比較常用到這種登錄模式,目的是為防止重復登錄。而其實現原理也頗為簡單,只要Cache的形式就可以實現,這里只用于簡單記錄下,呵呵……
代碼如下:
復制代碼 代碼如下:

///單點登錄(Single Sign On)
public void SSOMethods(string username, string password)
{
//判斷登錄情況 此處方法省略……
int result = CheckLogin(username, password);
if(result>0)
{
//唯一標識,可自行設定
string key = string.Format("{0}_{1}",username, password);
//得到Cache中的key值
string userCache = Cache[key].ToString();
//判斷是否為空
if(string.IsNullOrEmpty(userCache))
{
TimeSpan SessionTimeOut = new TimeSpan(0,0,HttpContext.Current.Session.TimeOut,0,0);
HttpContext.Current.Cache.Insert(key,key,null,DateTime.MaxValue,SessionTimeOut,CacheItemPriority,NotRemovable,null);
Session["User"] = key;
Response.Write("<font color=red>登錄成功!</font>");
}
else
{
Repsonse.Write("<font color=red>抱歉,您已經在其他地方登錄了!</font>");
return;
}
}
else
{
Response.Write("用戶名不存在!");
}
}

相關文章

最新評論