I am facing an issue with my Angular application where cookies are not being read properly in Internet Explorer 11. The JavaScript code works fine on Chrome, but IE seems to be having trouble accessing the cookie data even though it is visible in the developer tools and not set to HTTP only. I have already checked that all cookies are enabled on IE.
If anyone has any insights or suggestions on why IE is behaving this way with my app, I would greatly appreciate the help.
Below is how I set the cookie in my controller:
HttpResponseMessage response = new HttpResponseMessage();
JsonMediaTypeFormatter json = new JsonMediaTypeFormatter();
response.Content = new ObjectContent<PvUser>(MyPOCO, json, "application/json");
var cookie = new CookieHeaderValue(cookieName, cookieValue);
cookie.Domain = Request.RequestUri.Host;
cookie.Expires = DateTimeOffset.Now.AddMinutes(20);
cookie.HttpOnly = false;
response.Headers.AddCookies(new CookieHeaderValue[] { cookie });
And here is the code snippet from w3schools that I am using to retrieve a cookie by its name:
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
}
return "";
}