我的登录页面上有以下代码:
if (authentication method returns true)
{
FormsAuthenticationTicket ticket;
if (cbRemember.Checked)
{
ticket = new FormsAuthenticationTicket(1, tbUsername.Text, DateTime.Now, DateTime.Now.AddYears(1), true, null, FormsAuthentication.FormsCookiePath);
}
else
{
ticket = new FormsAuthenticationTicket(1, tbUsername.Text, DateTime.Now, DateTime.Now.AddHours(1), true, null, FormsAuthentication.FormsCookiePath);
}
string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
cookie.HttpOnly = true;
Response.Cookies.Add(cookie);
}
else
{
errorBox.Visible = true;
}
但是,此后用户仍未通过身份验证。我做错了吗?
答案 0 :(得分:0)
问题在于我将null
传递给了其中一个故障单的参数。你必须传递string.empty。