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

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");

Leave a Comment