对预检请求的响应未通过访问控制检查:asp-net core

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

我知道这是一个着名的错误,但在尝试各种解决方案后我无法修复它。

我发送的请求是通过Angular 2应用程序。这是客户端请求的代码:

async registerAdmin(admin: SystemAdminRegistrationViewModel) {

    let response = await this.http.post(this.Account_API_URL + 'accounts/createaccount', admin).toPromise();
    return response;
}

我正在使用asp.net core 2 web api项目进行API。在我的Startup.cs类中,我有这个:

    services.AddCors(o => o.AddPolicy("MyPolicy", build =>
            {
                build.AllowAnyOrigin()
                       .AllowAnyMethod()
                       .AllowAnyHeader();
            }));



            app.UseCors("MyPolicy");

编辑

我忘了提到当我在本地运行API时请求工作正常,但是错误显示请求由Azure托管的远程服务器。

angular asp.net-web-api http-headers
1个回答
0
投票

如果您使用的是Angular 6,则可以配置proxy.conf,它将充当您的后端API URL的代理。有关更多信息,请参阅此文档链接https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md

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