Redeem Cookie values

0

Good afternoon I have an application in MVC that generates some cookies, I would like to know if it is possible to recover these cookies through an Api, as I tried and unfortunately could not.

Code generated for api:

[Route("ResgataCookie")]
[HttpGet]
public IHttpActionResult ResgataCookie()
{
    string test = "";
    if (HttpContext.Current.Request.Cookies["RMACookies"] != null)
    {
        test = HttpContext.Current.Request.Cookies["RMACookies"].Value;
    }

    return Ok(test);
}

Follow the image below:

    
asked by anonymous 25.09.2018 / 21:27

1 answer

0

Cookies in the WebAPI can be accessed using Request.Headers.GetCookies

See the documentation at link

Follow the example below

[HttpGet]
[Route("ResgataCookie")]
public IHttpActionResult ResgataCookie()
{
  var cookies = Request.Headers.GetCookies().FirstOrDefault();

  if (cookies == null || !cookies.Cookies.Any(p => p.Name == "RMACookies"))
    return NotFound();

  var item = cookies.Cookies.First(p => p.Name == "RMACookies").Value;

  return Ok(item);
}
    
25.09.2018 / 22:10