我想安装使用ASP.NET 4Asp.Net 4 Response.Cookies.Add不添加饼干到用户机器
我知道我的验证代码(代码,如果用户名,检查基本窗体身份验证和密码是正确的)正在工作,因为如果用户输入无效信息后ReturnLable告诉他们。但是,如果他们输入了正确的信息,则会将其重定向到受限制的页面,并显示403 - 禁止的错误。当我检查了壳:虽然我把它添加到集合中没有Cookie已写入甚至Cookie路径“Response.Cookies.Add(饼干);”
protected void Submit_Click(object sender, EventArgs e)
{
Email.Text = Email.Text.Trim();
Password.Text = Password.Text.Trim();
if (IsValid(Email.Text, Password.Text)) //user exists
{
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
Email.Text,
DateTime.Now,
DateTime.Now.AddMinutes(50),
RememberMe.Checked,
"user",
FormsAuthentication.FormsCookiePath);
string hashCookies = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
Response.Cookies.Add(cookie);
}
else
{
ReturnLable.Text = "<font color=red> Username/Password Incorrect Please Try Again </font>";
ReturnLable.Visible = true;
}
,你是男人! – user889829
很高兴这解决了这个问题!如果您单击此答案旁边的复选标记形状的图像,它将“接受”它作为解决问题的答案。接受答案是很好的stackoverflow-citizenship。 – mikemanne
+1作为最佳答案 –