加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

单一登陆的例子

发布时间:2020-12-13 20:28:39 所属栏目:百科 来源:网络整理
导读:单一登陆就是一个帐号只能在一个地方登陆。后登陆的帐号会把前面登陆的帐号踢走。注意,只是介绍思路,代码很乱。 login.aspx.cs protected void Button1_Click( object sender,EventArgse) { Session[ " name " ] = TextBox1.Text; if (Cache[ " userlist "

单一登陆就是一个帐号只能在一个地方登陆。后登陆的帐号会把前面登陆的帐号踢走。注意,只是介绍思路,代码很乱。

login.aspx.cs

protected void Button1_Click( object sender,EventArgse)
{
Session[
" name " ] = TextBox1.Text;
if (Cache[ " userlist " ] == null )
{
System.Collections.Generic.Dictionary
< string , string > userlist = new System.Collections.Generic.Dictionary < string , string > ();
userlist.Add(Session[
" name " ].ToString(),Session.SessionID);
Cache[
" userlist " ] = userlist;
}
else
{
System.Collections.Generic.Dictionary
< string , string > userlist = Cache[ " userlist " ] as System.Collections.Generic.Dictionary < string , string > ;
userlist[Session[
" name " ].ToString()] = Session.SessionID;
Cache[
" userlist " ] = userlist;
}
Response.Redirect(
" default.aspx " );
}


default.aspx.cs

protected void Page_Load( object sender,EventArgse)
{
if (Session[ " name " ] == null )
Response.Write(
" <script>alert('请登陆');location.href='login.aspx';</script> " );
else if ((Cache[ " userlist " ] as System.Collections.Generic.Dictionary < string , string > )[Session[ " name " ].ToString()] != Session.SessionID)
Response.Write(
" <script>alert('已经有相同帐号登陆');location.href='login.aspx';</script> " );}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读