【发布时间】:2015-10-15 10:31:40
【问题描述】:
我的 Asp.Net5 Web Api 无法在 Chrome 上运行,这是由于 CORS 问题,似乎我的 CORS 配置与我的 OAuthBearerAuthentication 冲突。 在我的 Startup.cs 中:
services.AddCors();
services.ConfigureCors(o => o.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()));
我的控制器看起来像:
[Authorize(OAuthBearerAuthenticationDefaults.AuthenticationScheme)]
[EnableCors("AllowAll")]
public class MyController
然后我得到No 'Access-Control-Allow-Origin' header is present on the requested resource.
但是,如果我删除了授权属性:
[EnableCors("AllowAll")]
public class MyController
那我就被允许了……这是怎么回事?
【问题讨论】:
-
你是如何解决这个问题的?
-
很遗憾,我没有
标签: asp.net cors asp.net-core-mvc