现在的位置: 首页 > 综合 > 正文

一个帐号在一定的时间里只能登录一次

2012年09月25日 ⁄ 综合 ⁄ 共 1248字 ⁄ 字号 评论关闭

 protected void btLogic_Click(object sender, EventArgs e)
    {
        c.userName = txtName.Value;
        c.PWD = txtPWD.Value;
        if(Convert.ToInt32( BusinessDAL.CheckUser(c))==1)
        {
            //Session["userName"] = txtName.Value;
            //Session.Timeout = 100;
            CheckLogic();
            Response.Redirect("Default.aspx");
        }
        else
        {
            Response.Write("<script>alert('输入有误请重新输入');window.location.href='logic.aspx'</script>");
        }

    }

    /// <summary>
    ///  一个帐号在一定的时间里只能登录一次
    /// </summary>
    public void CheckLogic()
    {
        string strUser = string.Empty;
        string cahStrKey = this.txtName.Value;
        strUser = Convert.ToString(Cache[cahStrKey]);

        if (strUser == string.Empty)
        {//表示还没有登录
           // Session["userName"] = txtName.Value;
            Session.Timeout = 100;
            TimeSpan timeOut = new TimeSpan(0,0,Session.Timeout);
            Cache.Insert(cahStrKey, cahStrKey, null, DateTime.MaxValue, timeOut, CacheItemPriority.NotRemovable, null);
            Session["userName"] = cahStrKey;
            Response.Write(Session["userName"].ToString());
        }

        else
        {

            Response.Write("你已经登录"+"<script language='javascript'>window.location.href='Default.aspx';</script>");
            Response.End();
        }

    }

抱歉!评论已关闭.