I am generating a token in web api using FormsAuthenticationTicket, like that:
var user_json_str = new JavaScriptSerializer().Serialize(user);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
user.UserId,
DateTime.Now,
DateTime.Now.AddMinutes(30), false,
user_json_str, FormsAuthentication.FormsCookiePath);
string encTicket = FormsAuthentication.Encrypt(ticket);//ENCRYPT THE TICKET
after that, I try to return it to the user in the response header like that:
HttpContext.Current.Response.Cookies.Add(new HttpCookie("encTicket", encTicket));
I found the cookie in the client after that.
I read somewhere, that it's not suggested to use web api like that, so I tried this way:
string encTicket = FormsAuthentication.Encrypt(ticket);//ENCRYPT THE TICKET
HttpResponseMessage ans = new HttpResponseMessage();
ans = new HttpResponseMessage(HttpStatusCode.OK);
ans.Content = new StringContent("Logged");
ans.Headers.AddCookies(new[] { new CookieHeaderValue("encTicket", encTicket) });
return ans;
this time the cookie didn't appear in the client ( I tried to read it using document.cookie in the chrome console).
what is the correct way to send cookie in the response header from web api?