You are designing a C# backend service to update a custom metadata tag on a blob in Azure Blob Storage. The target blob is currently protected by an active write lease. The operation must be authenticated using a Shared Access Signature (SAS) token adhering to the principle of least privilege, and the updated metadata value must be verified immediately after. Which C# code segment should you use to successfully perform this operation?
- var sas = new BlobSasBuilder { ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(15) };
sas.SetPermissions(BlobSasPermissions.Read | BlobSasPermissions.Write);
var client = new BlobClient(blobUri, sas.ToSasQueryParameters(credential));
await client.SetMetadataAsync(new Dictionary<string, string> { { "Department", "Finance" } }, new BlobRequestConditions { LeaseId = leaseId });
var dept = (await client.GetPropertiesAsync()).Value.Metadata["department"];Cevap - Bvar sas = new BlobSasBuilder { ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(15) };
sas.SetPermissions(BlobSasPermissions.Read | BlobSasPermissions.Write);
var client = new BlobClient(blobUri, sas.ToSasQueryParameters(credential));
await client.SetMetadataAsync(new Dictionary<string, string> { { "Department", "Finance" } });
var dept = (await client.GetPropertiesAsync()).Value.Metadata["department"]; - Cvar sas = new BlobSasBuilder { ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(15) };
sas.SetPermissions(BlobSasPermissions.Read | BlobSasPermissions.Write);
var client = new BlobClient(blobUri, sas.ToSasQueryParameters(credential));
await client.SetMetadataAsync(new Dictionary<string, string> { { "Department", "Finance" } }, new BlobRequestConditions { LeaseId = leaseId });
var dept = (await client.GetPropertiesAsync()).Value.Metadata["Department"]; - Dvar sas = new BlobSasBuilder { ExpiresOn = DateTimeOffset.UtcNow.AddDays(30) };
sas.SetPermissions(BlobSasPermissions.All);
var client = new BlobClient(blobUri, sas.ToSasQueryParameters(credential));
await client.SetMetadataAsync(new Dictionary<string, string> { { "Department", "Finance" } }, new BlobRequestConditions { LeaseId = leaseId });
var dept = (await client.GetPropertiesAsync()).Value.Metadata["department"];
Cevap
The C# code segment that configures a SAS token with 15 minutes expiration and Read/Write permissions, includes the active Lease ID in the request conditions when calling SetMetadataAsync, and retrieves the metadata value using the lowercase key "department".
The correct implementation creates a SAS token with the minimum required permissions (Read and Write) and a short duration (15 minutes). When calling SetMetadataAsync, the active lease ID must be passed via the BlobRequestConditions parameter to prevent a lease-conflict failure. Finally, because Azure Blob Storage stores and returns metadata keys in lowercase, retrieving the value requires querying the Metadata dictionary with the lowercase key 'department'.
Adım Adım Çözüm
Anahtar Kavram
Managing Blob Metadata, Lease Handling, and SAS Authorization in C#
Tahmini Süre:1m 30s