0

So, I created my client application using angular to interact with my WCF REST API. I basically use cookies to store the login session and retrieve the information by sessions. This works perfectly from Postman and also with a console client application (there I created cookie container).

Now I have a problem to read the cookies from AngularJs. My HTTP response header shows the cookies but the angular response header is undefined.

AngularService.js:

this.login = function (credential) {
    var request = $http({
        method: "POST",
        url: "someUrlLogin",
        data: angular.toJson(credental),
        config: { withCredentials: true },
    });
    return request;
}

AngularContoller.js :

 var promisePost = AngularService.login(credential);
    promisePost.then(function (response) {

        $scope.loginResult = angular.fromJson(response);
        $timeout(function () {

            console.log(response.headers("Set-Cookie"); //null
            console.log($cookies["ASP.NET_SessionId"]); //undefined
            console.log($cookies.getAll); //undefined
        },
        function error (err) {
            $scope.loginResult = err;
        });

WCF REST session:

 _context.Session["USERLOGGEDIN"] = "SomeValue"
  • I have set the HTTPOnly flag to false
  • I have also tried "console.log(response.headers("setcookie") which also doesn't work
  • "Access-Control-Allow-Credentials = true"
  • "Access-Control-Expose-Headers" value="content-type, Set-Cookie"

What else am I missing? Is it even possible to read the cookies from the http response headers?

0 Answers0