Asp.net Windows身份验证正在摆脱CORS?
我在使用windows身份验证时遇到问题,需要飞行前请求才能登录。然而,尽管在我的启动文件中启用了CORS,但应用程序仍将无法满足飞行前的“允许访问控制源”要求 未能加载:对飞行前的响应 请求未通过访问控制检查:否 “Access Control Allow Origin”标头出现在请求的服务器上 资源。因此,不允许使用源“” 进入 我在本地运行SPA主机:8080 我有一个axios的帖子,里面有证书Asp.net Windows身份验证正在摆脱CORS?,asp.net,cors,Asp.net,Cors,我在使用windows身份验证时遇到问题,需要飞行前请求才能登录。然而,尽管在我的启动文件中启用了CORS,但应用程序仍将无法满足飞行前的“允许访问控制源”要求 未能加载:对飞行前的响应 请求未通过访问控制检查:否 “Access Control Allow Origin”标头出现在请求的服务器上 资源。因此,不允许使用源“” 进入 我在本地运行SPA主机:8080 我有一个axios的帖子,里面有证书 function identityLogin () { const url = BASE
function identityLogin () {
const url = BASE_URL + 'api/token'
axios.get(url, {withCredentials: true}).then(response => {
if (response.statusText === 'OK') {
.....
} else {
....
}
})
.catch(error => {
console.log(error)
....
})
}
在我的startup.cs中,我有
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
);
app.UseMvc();
当我第一次获得windows凭据时,一位以前的开发人员写道:
[HttpGet("api/token")]
[Authorize]
public async Task<IActionResult> Get()
{
this.Response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:8080");
this.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type,Authorization");
this.Response.Headers.Add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
this.Response.Headers.Add("Access-Control-Allow-Credentials", "true");
.........
}
在startup.cs中订购物品
app.usecor
必须在app.UseMvc
之前:
app.UseCors(builder => builder
.WithOrigins("http://localhost:8080")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
app.UseMvc();
app.UseCors(builder => builder
.WithOrigins("http://localhost:8080")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
app.UseMvc();