asp.net 簡單單點登錄技術分析
更新時間:2011年02月14日 21:58:05 作者:
單點登錄,又叫SSO(Single Sign On)。在一些cms或者OA中比較常用到這種登錄模式,目的是為防止重復登錄。而其實現(xiàn)原理也頗為簡單,只要Cache的形式就可以實現(xiàn),這里只用于簡單記錄下,呵呵……
代碼如下:
///單點登錄(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("用戶名不存在!");
}
}
復制代碼 代碼如下:
///單點登錄(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("用戶名不存在!");
}
}
相關文章
國產化之Arm64?CPU+銀河麒麟系統(tǒng)安裝.NetCore的步驟詳解
這篇文章主要介紹了國產化之Arm64?CPU+銀河麒麟系統(tǒng)安裝.NetCore,這里就以ARM架構舉例,其它CPU平臺的安裝過程都一樣,要下載的包不同而已,感興趣的朋友跟隨小編一起看看吧2022-03-03
Community Server專題三:HttpModule
Community Server專題三:HttpModule...2007-03-03
Coolite Cool Study 1 在Grid中用ComboBox 來編輯數(shù)據(jù)
作為Coolite的第一個教程,我想展現(xiàn)給大家能夠體現(xiàn)Coolite強大的例子(當然也比官方例子稍微復雜一點)。2009-05-05

