1、Startup
中,添加一个变量
readonly string ganweiCosr = "AllowSpecificOrigins";
2、readonly string ganweiCosr = "AllowSpecificOrigins";
services.AddCors(options =>
{
options.AddPolicy(ganweiCosr,
builder => builder.AllowAnyHeader()
.AllowAnyMethod()
.AllowAnyOrigin());
});
3、中间件加
app.UseRouting();
app.UseCors(ganweiCosr);
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers().RequireCors(ganweiCosr);
endpoints.MapControllers();
}