使用IIS CORS模块可以很好地解决问题。以下网址仅供参考。
使用Windows身份验证 虽然这绝不是CORS模块解决的唯一方案,但重要的是要保证呼叫。以前,如果您尝试向使用Windows身份验证的应用程序发出跨域请求,则预检请求将失败,因为浏览器未发送带有预检请求的凭据。如果不在应用程序中启用匿名身份验证,则无法解决此问题。由于CORS模块在认证之前启动,因此可以在不影响应用程序安全模型的情况下处理飞行前请求。这是你的web.config可能是什么样子的一个例子。
https://blogs.iis.net/iisteam/getting-started-with-the-iis-cors-module
示例代码:
<?xml version="1.0" encoding="utf-8"?> <configuration> <!-- To customize the asp.net core module uncomment and edit the following section. For more info see https://go.microsoft.com/fwlink/?linkid=838655 --> <system.web> <authentication mode="Windows"/> </system.web> <system.webServer> <cors enabled="true" failUnlistedOrigins="true"> <add origin="http://localhost:60096" allowCredentials="true" > <allowHeaders allowAllRequestedHeaders="true"> <add header="Header1" /> </allowHeaders> </add> </cors> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\Project.Api.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" /> </system.webServer> </configuration>
这非常相似 启用CORS但是在POST JSON时,预检的响应具有无效的HTTP状态代码404 并提供了适合我的解决方案(我在POST请求时遇到401错误)。此外,不应同时配置NTLM和Negotiate( 协商V / s NTLM )。
看起来您想要传递凭证或与请求一起使用。
请检查 这个链接 用于添加凭据/允许用户凭据。
的 允许跨源凭据时要小心。另一个域的网站可以在用户不知情的情况下代表用户向应用程序发送登录用户的凭据。 CORS规范还指出,如果存在Access-Control-Allow-Credentials标头,则将原点设置为“*”(所有原点)无效。 强>