如何在第一个请求(Windows 身份验证)中使用授权 header 触发 AJAX post?

How can I fire an AJAX post with the Authorization header the first request (Windows Authentication)?

我有一个 Web 应用程序,它包含一个视频页面和一个将执行一些日志记录(页面加载、视频完成或页面关闭)的 Web API。我使用 ajax post:

触发这些事件
function logAction(actionToLog) {
    $.ajax({
        type: 'POST',
        url: "/api/v/" + currentVideoName + "/" + currentUser + "/" + vid.currentTime + "/" + actionToLog + "/" + currentBrowserType + "/",
        cache: false,
        contentType: 'application/json; charset=utf-8'
    });

使用 Fiddler,我注意到所有这些调用都被执行了两次:

Header 对于第一个(未经授权的 401)请求。没有授权令牌:

POST http://HOSTNAME/api/v/ValuePropVideo1/tfrick/0/started/Chrome/ HTTP/1.1
Host: HOSTNAME
Connection: keep-alive
Content-Length: 0
Cache-Control: max-age=0
Accept: */*
Origin: http://HOSTNAME
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
Content-Type: application/json; charset=utf-8
Referer: http://HOSTNAME/v/ValuePropVideo1
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8

Header 第二个(有效)请求。存在授权令牌:

Authorization: Negotiate YIII+QYGKwYBBQUCo...

这对于加载页面和完成视频来说效果很好,因为浏览器仍然打开,但是当我为关闭浏览器的用户发出 ajax 调用时,只发送第一个请求并且出现 401 错误收到。

我的问题是:如何使用 windows 凭据触发这些 ajax 调用?

在与这个问题斗争了很长时间之后,我决定进入 IIS 设置并在 "Authorization" 下的 "Windows Authentication" 的高级设置下删除 "Negotiate" 提供程序;只留下 NTML。这似乎解决了我的问题。

site->Authentication->Windows Authentication->Providers