Cookie not created
本文关键字:created not Cookie | 更新日期: 2023-09-27 18:01:37
你好,如果有以下代码:
protected void btnAdmLogin_Click(object sender, EventArgs e)
{
DBDataContext dc = new DBDataContext();
try
{
PortalUser login = dc.PortalUsers.Single(q => q.UserName.Equals(txtAdmLoginEmail.Text) && q.Password.Equals(txtAdmLoginPassw.Text));
if (HttpContext.Current.Request.Cookies["Cookie"] == null)
{
HttpCookie adcookie = new HttpCookie("Cookie");
adcookie.Expires = DateTime.Now.AddHours(24);
adcookie.Value = login.UserName + "-" + 1;
adcookie.Name = "Cookie";
HttpContext.Current.Request.Cookies.Add(adcookie);
}
HttpContext.Current.Response.Redirect("Overview");
}
这里错的部分是什么?
应该将cookie添加到Response对象而不是Request对象
HttpContext.Current.Response.Cookies.Add(adcookie);