Here's the script:
I created a web api project and an mvc project, for example:
http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
I installed CORS support via nuget and added EnableCorsAttribute
I ran the project and everything worked as expected (GET, PUT and POST) through Chrome, IE and FireFox.
Then I turned on Windows authentication in the web api project (yes, I really need win auth in the api project). To make this work, I added the xhrFields argument to my jquery.ajax call:
$.ajax({ type: method, url: serviceUrl, data: JSON.stringify(foo), contentType: 'application/json; charset=UTF-8', xhrFields: { withCredentials: true } }).done(function (data) { $('#value1').text(data); }).error(function (jqXHR, textStatus, errorThrown) { $('#value1').text(jqXHR.responseText || textStatus); });
In addition, I set the property EnableCorsAttribute.SupportsCredentials = true
I checked everything. Chrome and IE worked, FireFox did not. Firefox receives 401 in response to a preflight request (OPTIONS).
It seems that FireFox is not trying to authenticate with the service.
Has anyone found a solution to this problem?
ahanusa
source share