You should add the cookie to the Response object and not the Request object
HttpContext.Current.Response.Cookies.Add(adcookie);
سؤال
Hi there if have the following code:
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");
}
What is the wrong part In here? Its not creating anything.
المحلول
You should add the cookie to the Response object and not the Request object
HttpContext.Current.Response.Cookies.Add(adcookie);