利用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;
}
}