zoukankan      html  css  js  c++  java
  • 妙用Cache检验用户是否重复登陆

    //生成Key   
                string sKey = TextBox1.Text + "_IsLogin";
                
    //得到Cache中的给定Key的值   
                string sUser = Convert.ToString(Cache[sKey]);

                
    //检查是否存在   
                if (sUser == null || sUser == String.Empty)
                
    {
                    
    //Cache中没有该Key的项目,表明用户没有登录,或者已经登录超时      
                    
    //TimeSpan 表示一个时间间隔,获取系统对session超时作的设置值
                    
    //TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);
                    
    //(如果考虑到允许用户再次登陆的时间小于session超时时间,可将此值设小,在此示例中设置为一分钟) 
                    TimeSpan SessTimeOut = new TimeSpan(00100);
                    HttpContext.Current.Cache.Insert(sKey, sKey, 
    null, DateTime.MaxValue, SessTimeOut,
                                                     System.Web.Caching.CacheItemPriority.NotRemovable, 
    null);
                    
    //首次登录,您可以做您想做的工作了。   
                    Label1.Text = "你好!欢迎光临";
                }

                
    else
                
    {
                    
    //在Cache中发现该用户的记录,表名已经登录过,禁止再次登录   
                    Label1.Text = "对不起,你已在别处登陆.或者在1分钟后重试";
                    
    return;
                }
  • 相关阅读:
    蓝桥杯 全球变暖(dfs)
    Bzoj3196 Tyvj 1730 二逼平衡树
    Bzoj3110 [Zjoi2013]K大数查询
    Bzoj4004 [JLOI2015]装备购买
    Bzoj2115 [Wc2011] Xor
    Bzoj1257 [CQOI2007]余数之和sum
    HDU1724 Ellipse
    Bzoj2178 圆的面积并
    SPOJ CIRU The area of the union of circles
    CodeForces 232E.Quick Tortoise
  • 原文地址:https://www.cnblogs.com/hyd309/p/1440626.html
Copyright © 2011-2022 走看看