漫漫技术人生路

C#

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 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();
        }

    }

posted on 2006-09-25 13:25  javaca88  阅读(221)  评论(0编辑  收藏  举报