zoukankan      html  css  js  c++  java
  • ASP.NET 2.0防止同一用户同时登陆

    以下代码可以限制同一个帐号同时登录:

     1string key = TextBox1.Text; //用户名文本框设为cache关键字
     2        string uer = Convert.ToString(Cache[key]); //读取cache中用户相应的值
     3
     4        //判断cache中是否有用户的信息,如果没有相关的值,说明用户未登陆
     5        if (uer == null || uer == String.Empty)
     6        { //定义cache过期时间 
     7            TimeSpan SessTimeout = new TimeSpan(00, System.Web.HttpContext.Current.Session.Timeout, 00);
     8            //第一次登陆的时候插入一个用户相关的cache值, 
     9            HttpContext.Current.Cache.Insert(key, key, null, DateTime.MaxValue, SessTimeout, System.Web.Caching.CacheItemPriority.NotRemovable, null); Session["ADMINID"= TextBox1.Text; Response.Redirect("main.aspx");
    10        }

    11        else
    12        {
    13            //重复登陆 
    14            Response.Write("<script>alert('您的账号已经登陆!');window.location='login.aspx';</script>");
    15        }
  • 相关阅读:
    day35-python-网络编程
    oc-继承(inherit) 方法重写 继承与组合
    oc-self关键字
    oc-类方法
    oc-封装 get set方法
    oc-匿名对象
    oc-函数命名
    oc-函数,方法,类
    解决"authentication token manipulation error"
    让tomcat自动定位到项目
  • 原文地址:https://www.cnblogs.com/winsonet/p/772510.html
Copyright © 2011-2022 走看看