javascriptangularjscookiesasp.net-web-api2form-authentication

Can't access the WEB API Cookie via document.cookie in Javascript


I Implemented a AngularJS Project, Service Side implementation I used the .NET WEB API. For Authorization I'm using

FormsAuthentication.SetAuthCookie(token, false);

It's coming fine in browser Cookies.

enter image description here

enter image description here

But I can't able to get the cookies in JavaScript

enter image description here

Kindly assist me, why It's coming empty ?


Solution

  • The reason for this is that .MDAUTH cookie is set as HttpOnly. This means only the server side will be able to access the cookie and not the client side. You need to explicitly set HttpOnly to false while setting the cookie in the backend.