继续获取未授权的Web API

问题描述 投票:0回答:1

我有一个项目,这是一个需要Windows身份验证的Web应用程序。

我已经使用NAS虚拟化功能在家中设置了Active Directory。然后,我为IIS创建了VMWare服务器,该服务器是我的桌面上该域的成员,我也将其用于开发。我已经创建了Web API并将其安装到该VMWare服务器中。当我直接调用例程时,它可以工作并返回结果,但是当我从Javascript Web应用程序中使用Web API例程时,我不断收到401错误。然后,我将代码放在IIS服务器上,并且Web应用程序正常工作。

我已经看到了许多解决方案,例如更改IIS身份验证中提供程序的顺序。在文件夹上添加了所有人的读/写权限。我还在web.config上添加了条目。但是它们都不起作用。

*****根据评论的要求更新*****

下面是当我直接从Web API运行时

enter image description here

从Java调用Web APIenter image description here

enter image description here

这是我遇到的错误enter image description hereenter image description here

仅供参考,我尝试在同一台计算机上从Visual Studio运行Web api,但也出现401错误

enter image description here

我可以添加一些内容以使我的开发计算机受到信任吗?

************************更改代码后的新问题**********enter image description here

****************另一个更新******这绝对很奇怪,因此我安装了Fiddler 4以查看发生了什么。但是仍然没有运气。

然后我在IIS HTTP Response Header上进行了更改

enter image description here

enter image description here

奇怪的是,当我运行Fiddler时,错误消失了,但是当我关闭它时,错误又回来了。

iis asp.net-web-api windows-authentication http-status-code-401
1个回答
0
投票

这很可能发生,因为API是与网站本身不同的域名。要告诉它将凭据发送到跨域站点,您需要在JavaScript中发出请求时设置withCredentials选项。

使用jQuery,看起来像这样:

withCredentials
© www.soinside.com 2019 - 2024. All rights reserved.