Configure cors to allow all subdomains using ASP.NET Core (Asp.net 5, MVC6, VNext)

后端 未结 4 1660
甜味超标
甜味超标 2020-12-10 00:51

I have cors setup correctly in an ASP.NET Core web app. Im using the following package...

\"Microsoft.AspNet.Cors\": \"6.0.0-rc1-final\"

an

4条回答
  •  清歌不尽
    2020-12-10 01:31

    This has now been implemented in version 2.0.0. In your ConfigureServices use the following:

    options.AddPolicy("MyCorsPolicy",
       builder => builder
          .SetIsOriginAllowedToAllowWildcardSubdomains()
          .WithOrigins("https://*.mydomain.com")
          .AllowAnyMethod()
          .AllowCredentials()
          .AllowAnyHeader()
          .Build()
       );
    

    Also, don't forget to call UseCors in your Configure call too:

    app.UseCors("MyCorsPolicy");
    

提交回复
热议问题