-
I need to set CORS policy for Azure Blob Storage but I get an error var blobServiceClient = app.Services.GetRequiredService<BlobServiceClient>();
var properties = await blobServiceClient.GetPropertiesAsync(); //<--- Error already happens here
properties.Value.Cors =
new[]
{
new BlobCorsRule
{
MaxAgeInSeconds = 1000,
AllowedHeaders = "*",
AllowedMethods = "GET, PUT, POST, DELETE, OPTIONS",
AllowedOrigins = "https://myurl.com",
ExposedHeaders = "*"
}
};
// Act
await blobServiceClient.SetPropertiesAsync(properties); |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
@AndiRudi Any luck on this issue? I am in the same boat. |
Beta Was this translation helpful? Give feedback.
-
I empathize with the frustration, azure is difficult. You can look up the required role for the operation https://learn.microsoft.com/en-us/rest/api/storageservices/set-blob-service-properties?tabs=microsoft-entra-id#authorization Here's the role assignment you need to add. Least privileged built-in role: Storage Account Contributor If you're not using Aspire 9, upgrade and you can do something like this: |
Beta Was this translation helpful? Give feedback.
-
Would be great to have a possibility to add CORS rules as part of storage.ConfigureInfrastructure extension method. I need to allow a web app (that is a part of Aspire solution) to directly access blog storage (with Delegated SAS token). Now I manually need to configure CORS for storage account. |
Beta Was this translation helpful? Give feedback.
-
I made it working this way:
|
Beta Was this translation helpful? Give feedback.
I made it working this way: