简体   繁体   English

对预检请求的响应未通过访问控制(Angular 2-Web Api)

[英]Response to preflight request doesn't pass access control (Angular 2 - Web Api)

I've several projects that one of them is for Authentication. 我有几个项目,其中之一是用于身份验证。 However I've set CORS configuration, it still returns errors. 但是,我已经设置了CORS配置,它仍然返回错误。

Note: Web Api apps work with postman. 注意: Web Api应用程序可与邮递员一起使用。

Here is what I've done so far: 到目前为止,这是我所做的:

Startup.cs Startup.cs

[assembly: OwinStartup(typeof(LabelGenerator.Startup))]
namespace LabelGenerator {
    public partial class Startup {
        public void Configuration(IAppBuilder app) {
            ConfigOAuth(app);
            ConfigWebApi(app);
        }
    }
}

Startup.Auth.cs Startup.Auth.cs

namespace LabelGenerator {
    public partial class Startup {
        private void ConfigOAuth(IAppBuilder app) {
            OAuthBearerAuthenticationOptions oAuthServerOptions = new OAuthBearerAuthenticationOptions();
            // Token Generation
            app.UseOAuthBearerAuthentication(oAuthServerOptions);
        }

        private void ConfigWebApi(IAppBuilder app) {
            HttpConfiguration conf = new HttpConfiguration();
            WebApiConfig.Register(conf);
            app.UseWebApi(conf);

            // CORS
            app.UseCors(CorsOptions.AllowAll);
        }
    }
}

Web.config Web.config文件

<modules runAllManagedModulesForAllRequests="true">
  <remove name="ApplicationInsightsWebTracking" />
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>

According to this answer I changed this : 根据这个答案,我改变了这个:

private void ConfigWebApi(IAppBuilder app) {
    HttpConfiguration conf = new HttpConfiguration();
    WebApiConfig.Register(conf);
    app.UseWebApi(conf);

    // CORS
    app.UseCors(CorsOptions.AllowAll);
}

to this : 对此:

private void ConfigWebApi(IAppBuilder app) {
    HttpConfiguration conf = new HttpConfiguration();
    WebApiConfig.Register(conf);

    // CORS
    app.UseCors(CorsOptions.AllowAll);
    app.UseWebApi(conf);
}

And now CORS is working properly. 现在, CORS可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET Core Web API + Angular 对预检请求的响应未通过访问控制检查:预检请求不允许重定向 - ASP.NET Core Web API + Angular Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request Angular 6 - 对预检请求的响应未通过访问控制检查:没有“Access-Control-Allow-Origin”标头 - Angular 6 - Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header CORS WCF:对预检请求的响应未通过访问控制 - CORS WCF: Response to preflight request doesn't pass access control 对预检请求的响应未通过访问控制检查(Angular2) - Response to preflight request doesn't pass access control check (Angular2) 对预检请求的响应未通过访问控制检查:否&#39;Access-Control-Allow-Origin&#39; - Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' ASP.net核心信号器角度客户端,错误“对预检请求的响应未通过访问控制检查” - ASP.net core signalr angular client, error “Response to preflight request doesn't pass access control check” CORS:对预检请求的响应未通过访问控制检查:它没有 HTTP 正常状态 - CORS: Response to preflight request doesn't pass access control check: It does not have HTTP ok status 对预检请求的响应未通过访问控制检查:响应中“ Access-Control-Allow-Credentials”标头的值为“ - Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' 在 ASP.NET 中,对预检请求的响应未通过访问控制检查:No &#39;Access-Control-Allow-Origin&#39; 标头 - In ASP.NET, Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header .NET 5 对预检请求的响应未通过访问控制检查:没有'Access-Control-Allow-Origin' header 存在于请求的资源上 - .NET 5 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM