【发布时间】:2018-04-29 15:00:39
【问题描述】:
我有几个项目,其中一个是用于身份验证的。但是我设置了CORS 配置,它仍然返回错误。
注意:Web Api 应用可与邮递员配合使用。
这是我到目前为止所做的:
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
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
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
【问题讨论】:
标签: c# angular cors asp.net-web-api2 http-status-code-405