user3559224
user3559224

Reputation:

ajax call does not sent cookies to web api ( Very Strange issue in Web Api)

Hi this is my ajax code

function GetCurrentUserId() {

        return $.ajax({
            type: "GET",
            url: rootUrl + '/api/Common/CurrentDateAndUser',
            dataType: 'json',
            crossDomain: true,          
            success: function (data, textStatus, xmLHttpRequest) {
                return data[0];

            },
            error: function (xhr, ajaxOptions, thrownError) {
                toastr.error('Somthing is wrong', 'Error');
            },



        });

    }

When i run this code in IE Browser then i can see this result from quick watch

enter image description here

See the above image, There have a some cookies value in RequestHeader

But same time if i run my application in Chrome or Firefox

Then i got this result

enter image description here

I can't see any cookies values. Why? Why i can't see the cookie values when i ran my application in Chrome? How to work the ajax call with Chrome and firefox? I have spend one weeks for this work, i can't solve this. and also Stack overflow does not helps yet. Please share your knowledge to me. please dude's .

Even a small sliver of wood can help as a toothpick

Edit

This Question related to my previous question

Web Security in IE VS Chrome & Firefox (bug)

Upvotes: 4

Views: 1000

Answers (1)

bsb_coffee
bsb_coffee

Reputation: 7051

You need to explicitly tell IE to send the cookies to the server withCredentials: true

e.g.

 $.ajaxSetup({
    type: "POST",
    data: {},
    dataType: 'json',
    xhrFields: {
       withCredentials: true
    }
 });

Upvotes: 1

Related Questions