.net 6 处理跨域的三种方式:
1.方法里添加,允许跨域
HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
2.方法添加特性,允许跨域
[CustomCorsActionFilterAttribute]
3. program.cs 全局注入,允许跨域
builder.Services.AddCors(policy =>
{
policy.AddPolicy("CorsPolicy", opt => opt
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("X-Pagination"));
});
app.UseCors("CorsPolicy");
标签:opt,跨域,CorsPolicy,三种,policy,NET6 From: https://www.cnblogs.com/Echoxxx/p/17003754.html