zoukankan      html  css  js  c++  java
  • 实现单点登录

     1if(this.user.Text.Trim()!="" && this.pwd.Text.Trim()!="")
     2            {
     3                // 生成Key
     4                string sKey = user.Text + "_" + pwd.Text;
     5                // 得到Cache中的给定Key的值
     6                string sUser = Convert.ToString(Cache[sKey]);
     7                // 检查是否存在
     8                if (sUser == null || sUser == String.Empty)
     9                {
    10                    // Cache中没有该Key的项目,表名用户没有登录,或者已经登录超时
    11                    // 注意下面使用的TimeSpan构造函数重载版本的方法,是进行是否登录判断的关键。                
    12                    TimeSpan SessTimeOut = new TimeSpan(0,0,System.Web.HttpContext.Current.Session.Timeout,0,0);
    13                    HttpContext.Current.Cache.Insert(sKey,sKey,null,DateTime.MaxValue,SessTimeOut,System.Web.Caching.CacheItemPriority.NotRemovable,null);
    14                    Session["User"= sKey;
    15                    //首次登录,您可以做您想做的工作了。
    16                    Msg.Text="<h4 style='color:red'>嗨!欢迎您访问<a href='http://dotnet.aspx.cc/'>;【孟宪会之精彩世界】";
    17                    Msg.Text += "</a>,祝您浏览愉快!:)</h4>";
    18                }

    19                else
    20                {
    21                    // 在 Cache 中发现该用户的记录,表名已经登录过,禁止再次登录
    22                    Msg.Text="<h4 style='color:red'>抱歉,您好像已经登录了呀:-(</h4>";
    23                    return;
    24                }
  • 相关阅读:
    自定义dialog
    利用jquery实现自动登录
    文件的上传
    一些想法
    利用ajax实现分页效果
    自动化构建工具gulp的基础了解
    javascript模块化---requirejs
    交互ajax
    聊聊javascript的事件
    谈谈bootstrap在实践中的应用
  • 原文地址:https://www.cnblogs.com/crith/p/695667.html
Copyright © 2011-2022 走看看