0

im trying to set a cookie from within my WEB API controller. I've followed the following tutorial: HTTP Cookies in ASP.NET Web API

this is the code i got:

[Route("api/user/SetCookie")]
        [HttpGet]
        public HttpResponseMessage SetCookie()
        {
            HttpResponseMessage respMessage = new HttpResponseMessage
            {
                Content = new ObjectContent<string[]>(new string[] {"value1", "value2"}, new JsonMediaTypeFormatter())
            };
            CookieHeaderValue cookie = new CookieHeaderValue("session-id", "123")
            {
                Expires = DateTimeOffset.Now.AddHours(1),
                Domain = Request.RequestUri.Host,
                Path = "/"
            };
            respMessage.Headers.AddCookies(new CookieHeaderValue[] { cookie });
            return respMessage;
        }

the problem is I can't see that any cookie is being set. I've used fiddler,postman and chrome debugger and no cookie is being presented. Any help in fixing this issue is highly appreciated!

grimsan55
  • 265
  • 3
  • 4
  • 20

0 Answers0