1

This is my code for frontend which calls for my session

await fetch("https://localhost:5001/api/session", {
          method: "GET",
          credentials: "same-origin",
})

This is my code for the api when sets a session

[HttpGet]
public ActionResult<string> CallMe()
{
    HttpContext.Session.SetString("Who", "Doctor Who");
    return Ok();
}

This should set a cookie in my browser on call but nothing shows up there .Code when I try to get the cookie on my other controller

[HttpGet]
public ActionResult<string> CallMeToo()
{
    string a = HttpContext.Session.GetString("Who");
    return Ok();
}

This returns null after the set call I call this too.

Magnetron
  • 7,495
  • 1
  • 25
  • 41
  • seems CORS policy issue check this link https://stackoverflow.com/questions/31942037/how-to-enable-cors-in-asp-net-core. Also try to run application after removing `HttpContext.Session.GetString("Who")` – शेखर Jan 13 '21 at 08:22

1 Answers1

0

Solved by adding AllowCredentials on services.AddCors to allow cross-origin cookies