Asp.net core (版本.net 7)跨域问题

前端vue3调用时提示跨域问题,直接加入代码

 builder.Services.AddCors(options =>
{
    options.AddPolicy("any", builder =>
    {
        builder.SetIsOriginAllowed(_ => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
    });
});

builder.Services.AddCors(options =>
{
    options.AddPolicy("any", builder =>
    {
        builder.SetIsOriginAllowed(_ => true).AllowAnyMethod().AllowAnyHeader().AllowCredentials();
    });
});

var app = builder.Build();

// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseCors("any"); 
app.UseAuthorization();

app.MapControllers();

猜你喜欢

转载自blog.csdn.net/easyboot/article/details/129932449
今日推荐