调用ASP.NET Web API时,IIS中托管的Angular 11应用程序发行了CORS问题
我们有以下设置
Angular 11/TypeScript App :与SSL/TLS CERT托管( https )在IIS中托管,并将用户凭据(ntlm)发送到后端API,并使用withCredentials头将其发送到后端API 。 同样对于CORS,我们正在传递标题“访问控制 - 允许 - 孔”:'*'
asp.net web api(.net 6) :使用http.sys(支持NTLM)进行自托管(以支持NTLM)并使用 http 。 为了支持CORS,
builder.Services.AddCors(options => options.AddDefaultPolicy(b => b.SetIsOriginAllowed(_ => true)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()));
当Angular App呼叫后端API时,我们正在使用它,它会遇到与CORS相关的错误。
对飞行前请求的响应不通过访问控制检查:不允许重定向以送货前请求。
但是,当我们在没有SSL/TLS CERT的Angular应用程序IE HTTP的情况下运行Angular App时,它可以正常运行。
因此,此CORS问题是因为Angular App是HTTP,而后端API是HTTP?如果是,那么我们如何解决此问题?
提前致谢。
We have the following setup
Angular 11 / TypeScript app: Hosted in IIS with SSL/TLS cert (HTTPS) and sending user credentials (NTLM) to the backend API using withCredentials header.
Also for CORS we are passing header 'Access-Control-Allow-Origin' : '*'
Asp.Net Web API (.Net 6): Self-hosted using Http.Sys (to support NTLM) and using HTTP.
To support CORS, we are using this
builder.Services.AddCors(options => options.AddDefaultPolicy(b => b.SetIsOriginAllowed(_ => true)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()));
When the Angular App is making a call to the backend API, it is getting error related to CORS.
Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
But when we run Angular app without SSL/TLS cert i.e HTTP, then it works fine.
So this CORS issue, is it happening because Angular app is HTTPS and backend API is HTTP? If yes then how can we solve this issue?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TLS与非TLS请求的不匹配会引发这样的东西:
您会遇到此错误,因为前飞行选项请求是通过某种中间件路由重定向的(我假设)。
您可以在此处阅读有关如何配置选项前请求的选项。根据您的要求,有很多选择,因此我不会发布建议。
https://学习。 microsoft.com/en-us/aspnet/core/security/cors?view= aspnetcore-6.0#prefleflight-requests
The mismatch of TLS to non-TLS requests throws something like this:
You are getting this error because the preflight OPTIONS request is being redirected by some sort of Middleware routing (I assume).
You can read up on how to configure for OPTIONS preflight requests here. There is lots of options depending on your requirements, so I won't post a suggestion.
https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-6.0#preflight-requests