如何使用Windows身份验证在IIS上授权CORS预检请求 [英] How to authorize CORS preflight request on IIS with Windows Authentication

查看:510
本文介绍了如何使用Windows身份验证在IIS上授权CORS预检请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.net Core 2(Windows身份验证)上有一个API,并且在角度上有一个前端。
我做了一个cors配置来从SPA角度查询我的后端,但由于他没有识别信息,我因为预检而被阻止,因为他没有识别信息。

I have an API on ASP.net Core 2 (windows authentication) and a front on angular. I make a cors configuration to querying my backend from the SPA angular, but im blocked in cause of the preflight who are rejected from the IIS server because he don't have identification information.

错误消息:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://XXXXXX' is therefore not allowed access. The response had HTTP status code 401.

代码方面:

//MY HEADER
private headers = new Headers({
    'Content-Type': 'application/json', 
    'Access-Control-Allow-Credentials':'true',
    'Access-Control-Allow-Origin':'true'
});

//REQUEST
let options = new RequestOptions({headers:this.headers, withCredentials:true});
return this.http.get(this.tasksUrl,options).map(res=>res.json());

代码侧回:( Startup.cs)

code side back : (Startup.cs)

public void ConfigureServices(IServiceCollection services)
{
   services.AddCors();
   services.AddCors(options =>
   {
       options.AddPolicy("AllowSpecificOrigin",
            builder =>
            {
               builder.WithOrigins("http://theURLofTheFront:8080" )
               .AllowAnyMethod()
               .AllowAnyHeader()
               .AllowCredentials();
            });
   });
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();
        app.UseCors("AllowSpecificOrigin");
        app.UseMvc();
    }

我试试这个:

使用Windows身份验证返回HTTP 401的CORS预检请求

我添加了自定义标题来指定IIS上的'Acces-control-allow-origin',对我不起作用。

and i added custom header to specify the 'Acces-control-allow-origin' on IIS, dont work for me.

这对我不起作用:
https://blogs.msdn.microsoft.com/friis/2017/11/24/putting-it-all-together-cors-tutorial/

我无法删除默认授权规则。

I can't remove the default authorization rule.

我事先感谢你

推荐答案

我解决了我的问题IIS模块Cors的问题

I solved my problem with the IIS module Cors

这篇关于如何使用Windows身份验证在IIS上授权CORS预检请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆