[英]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.