当前位置:编程学习 > C#/ASP.NET >>

asp.net登陆问题

用asp.net开发的一个系统
要登陆很多次才能登陆成功
退出也是要退很多次才能退出成功


登陆代码:
 protected void Button1_Click(object sender, EventArgs e)
    {
        string uname = this.txtuname.Text;
        string upass = MD5.EncryptPassword(this.txtupass.Text, "MD5");
        Db_user user = Db_userManager.Login(uname, upass);
        if (user != null && user.Ustatus == 1)
        {
            //记住我的名字
            if (!string.IsNullOrEmpty(Request["jizhuwo"]))
            {
                HttpCookie Cookie = CookiesHelper.GetCookie("UserInfo");
                if (Cookie == null)
                {
                    Cookie = new HttpCookie("UserInfo");
                    Cookie.Values.Add("uName", uname);
                    Cookie.Values.Add("uPass", upass);
                    //设置Cookie过期时间
                    Cookie.Expires = DateTime.Now.AddDays(7);
                    CookiesHelper.AddCookie(Cookie);
                }
                else if (Cookie.Values["uName"].Equals(uname) && Cookie.Values["uPass"].Equals(upass))
                {
                    CookiesHelper.SetCookie("UserInfo", "uName", uname);
                    CookiesHelper.SetCookie("UserInfo", "uName", upass);
                }

            }
            Session["USER"] = user;
            Response.Redirect("~/Default.aspx");
        }
        else if (user != null && user.Ustatus == 0)
        {
            this.ClientScript.RegisterStartupScript(this.Page.GetType(), "操作提示", "alert('您好您的账号还没有激活');", true);
        }
        else
        {
            this.ClientScript.RegisterStartupScript(this.Page.GetType(), "操作提示", "alert('您输入的用户名或密码错误,请重新输入');", true);
        }

    }


 //退出代码:
    protected void LbExit_Click(object sender, EventArgs e)
    {
        Session.Remove("USER");
        string cookname;
        HttpCookie hc;
        int k = Request.Cookies.Count;
        for (int i = 0; i < k; i++)
        {
            cookname = Request.Cookies[i].Name;
            hc = new HttpCookie(cookname);
            hc.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(hc);
        }
        Response.Redirect("~/Default.aspx");
    }


哪位高手指点一下 --------------------编程问答-------------------- 。。。是不是按钮坏了。。。。悲剧。! --------------------编程问答--------------------
引用 1 楼 wxr0323 的回复:
。。。是不是按钮坏了。。。。悲剧。!

精辟! --------------------编程问答-------------------- 你这个逻辑写的。。。蛋疼啊。。 --------------------编程问答-------------------- 把电cookies清楚一下再试试?! --------------------编程问答-------------------- 单步跟踪
 protected void ImgbtnClick(object sender, ImageClickEventArgs e)
        {
            if (Page.IsValid)
            {
                Sys_User user = SysUserBLL.SelectByUserId(Util.FormatInputStr(this.txtUser.Text));
                if (user != null)
                {
                    if (!user.PassWord.Equals(txtPwd.Text.Trim()))
                    {
                        new Jscript(this, "您输入的密码不对!").Show();
                        return;
                    }
                    else
                    {
                  
                        Session.Add("UserId", user.UserId);
                        Session.Add("UserName", user.UserName);
                   
                        this.Response.Write("<script language='javascript'>window.open(‘index.aspx','_self')</script>");
                    }
                }
                else
                {
                    new Jscript(this, "您没有任何权限!").Show();
                     return;
                }
            }
        } --------------------编程问答--------------------
引用 1 楼 wxr0323 的回复:
。。。是不是按钮坏了。。。。悲剧。!

/upload/20131227/52.gif --------------------编程问答--------------------
引用 6 楼 tao145 的回复:
引用 1 楼 wxr0323 的回复:
。。。是不是按钮坏了。。。。悲剧。!

/upload/20131227/52.gif

--------------------编程问答-------------------- 我还是赞同楼上说的,你运用调试单步执行一下嘛,看一下他是在哪里至跳出了的,或者没有执行,跟着程序的步骤走一遍就什么都清晰了。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,