I have tried many different says to add a cookie to a HttpContext.Current.Response with no luck. The browser does not see the cookie that I am adding. Help Please!
Here is my API Controller
public IHttpActionResult Get(string username, string password)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "*");
//This does not work
HttpCookie cookie = new HttpCookie("ACA-Cookie", "This better work!");
cookie.Expires = DateTime.Now.AddDays(2);
cookie.Domain = Request.RequestUri.Host;
cookie.Path = "/";
HttpContext.Current.Response.SetCookie(cookie);
//This does not work
var cookie = new HttpCookie("MyCookie", DateTime.Now.ToLongTimeString());
HttpContext.Current.Response.Cookies.Add(cookie);
return Ok(HttpStatusCode.OK);
}
Aucun commentaire:
Enregistrer un commentaire