I'm simply making an AJAX
GET request to my WebAPI method - IE is fine, but Chrome and Firefox return a 401 Unauthorized error.
Here's my jQuery, client-side code that makes the AJAX
call to my WebAPI:
(function ($) {
$.displayToastrNotifications = function (appId) {
$.support.cors = true;
var userId = '';
// get current user's ID
$.ajax({
url: 'http://server/AppTools/API/Identity/GetCurrentlyLoggedInUserId',
type: 'GET',
dataType: 'text',
crossDomain: true,
success: function (data) {
userId = data;
// get all messages for the app
$.ajax({
url: 'http://server/AppToolsWS/api/BulletinBoard/GetMessagesForApp/' + appId,
type: 'GET',
dataType: 'json',
crossDomain: true,
success: function (data) {
DisplayToasterNotifications(data);
},
error: function (x, y, z) {
alert('getmessagesforapp: ' + x + '\n' + y + '\n' + z);
}
});
},
error: function (x, y, z) {
alert('getuserid: ' + x + '\n' + y + '\n' + z);
}
});
...
And here's my WebAPI method:
[EnableCors("*", "*", "*")]
public class IdentityController : ApiController
{
[HttpGet]
public HttpResponseMessage GetCurrentlyLoggedInUserId()
{
var userid = string.Empty;
try
{
userid = HelperClasses.StringHelper.GetLogonUserID();
}
catch (Exception ex)
{
}
return this.Request.CreateResponse(HttpStatusCode.OK, userid, "text/plain");
}
}
I can manually navigate to this method in any browser and it returns data back successfully. It's weird, I'm not sure why it's doing this in Firefox and Chrome - I am on a company intranet using AD - any ideas?