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                }
  • 相关阅读:
    python相关的报错处理
    各版本数据库初次登录时,强制修改密码
    机器被感染病毒文件zigw的处理流程
    Let's encrypt申请泛域名证书以及报错处理
    添加/修改保存
    request.getRemoteUser() Spring Security做权限控制后
    hibernate hbm.xml配置映射
    hibernate 注解配置<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/X
    Web.xml配置详解之context-param
    在web.xml中通过contextConfigLocation配置spring
  • 原文地址:https://www.cnblogs.com/crith/p/695667.html
Copyright © 2011-2022 走看看