您的位置: bluesailor散记——
« 在asp.net中的detailview的编辑状态,运用dropdownlist在asp.net中统计字符串A在字符串B中出现的次数 »

asp.net中login控件,RememberMe可能是个bug

分类: .net学习调试笔记 发布: admins 浏览: 日期: 2008年10月19日

利用vs2008中的login控件时,转成模板,后台却得不到RememberMe的值。

public partial class userlogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Login1.DestinationPageUrl = "LoginMessage.aspx";

            if (Request.IsAuthenticated == true)
            {
                Response.Redirect(Login1.DestinationPageUrl);
            }
           
           
        }

        protected void userLogin_Authenticate(object sender, AuthenticateEventArgs e)
        {
            string strUserName = Login1.UserName;
            string strPassWord = FormsAuthentication.HashPasswordForStoringInConfigFile(Login1.Password, "MD5");
            CheckBox rm = (CheckBox)Login1.FindControl("RememberMe");//估计是个微软的bug
           
            string[] ReResult = Users.ValidateUserNameAndPwd(strUserName, strPassWord);
            string ReStr = ReResult[1];

            switch (ReStr)
            {
                case "noUser":
                    e.Authenticated = false;
                    break;
                case "ErrorPWD":
                    e.Authenticated = false;
                    break;
                case "Access":
                    HttpCookie objCookie = new HttpCookie("UserInfo");
                    Response.Cookies.Remove("UserInfo");
                    objCookie.Values.Add("UserName", strUserName);
                    objCookie.Values.Add("UserPwd", strPassWord);
                    objCookie.Values.Add("UserID", ReResult[0]);
                    if (rm.Checked)
                    {
                        objCookie.Expires = DateTime.Now.AddDays(15);
                    }

                    Response.AppendCookie(objCookie);

                    e.Authenticated = true;
                    break;
            }           
             
        }

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog 1.8 Spirit Build 80722

Copyright Lunji.com Some Rights Reserved.