Search code examples
c#azureazure-sdk

create cors entry for webapp with azure management fluent library


How to specify CORS settings for an existing Azure web app from Azure Management Fluent. Is there a code example?

The following code does not work. (siteconfig is null)

IWebApp app = AzureCloud.WebApps.List().FirstOrDefault(s = > s.Name == "myapp");
if (!app.Inner.SiteConfig.Cors.AllowedOrigins.Contains(ao)) 
{
    app.Inner.SiteConfig.Cors.AllowedOrigins.Add(ao);
    app.Update().Apply();
}

Solution

  • Refer to this article.

     SiteConfigResourceInner siteConfig = new SiteConfigResourceInner();
     siteConfig.Cors.AllowedOrigins.Add(ao);
     azure.WebApps.Inner.CreateOrUpdateConfigurationAsync(resourceGroup, app.Name, siteConfig);