netcore 跨域配置

分类: NetCore
  1. const string policyName = "CorsPolicy";
  2. //添加跨域配置,加载进来,启用的话需要使用Configure
  3. services.AddCors(options =>
  4. options.AddPolicy(policyName, builder =>
  5. {
  6. builder
  7. .AllowAnyHeader()
  8. .AllowAnyOrigin()
  9. .AllowAnyMethod();
  10. //builder.AllowCredentials(); 该方法不能和AllowAnyOrigin 同时使用,否则会触发异常:The CORS protocol does not allow specifying a wildcard (any) origin and credentials at the same time. Configure the CORS policy by listing individual origins if credentials needs to be supported
  11. })
  12. );
  1. const string policyName = "CorsPolicy";
  2. //支持跨域
  3. app.UseCors(policyName);
标签: NetCore

上一篇: netcore web api 签名封装(中间件统一签名&方法签名)

下一篇: netcore dockfile的配置

by 2023-08-07 23:49:07
篇笔记

学习笔记