You are developing a C# console application that uses the Azure.Storage.Blobs SDK (v12). The application retrieves properties for a blob container that has a custom metadata key named `Owner` set to `DevOps`.
You execute the following code to retrieve the container properties:
csharp
var containerClient = new BlobContainerClient(connectionString, "production-logs");
var properties = await containerClient.GetPropertiesAsync();
You need to extract the value of the `Owner` metadata field both directly from the SDK properties dictionary and from the raw HTTP headers.
Which two code segments should you use?
- properties.Value.Metadata["Owner"]Cevap
- Bproperties.Value.Metadata["x-ms-meta-Owner"]
- properties.GetRawResponse().Headers.TryGetValue("x-ms-meta-owner", out string value)Cevap
- Dproperties.GetRawResponse().Headers.TryGetValue("Owner", out string value)
Cevap
To retrieve the metadata value using the properties dictionary, access the key directly without the prefix, such as properties.Value.Metadata["Owner"]. To retrieve the metadata from the raw HTTP response headers, search using the full prefix, such as properties.GetRawResponse().Headers.TryGetValue("x-ms-meta-owner", out string value).
When retrieving custom metadata via the C# SDK, the Azure.Storage.Blobs SDK maps HTTP headers starting with x-ms-meta- into the Metadata dictionary and removes the prefix. Therefore, properties.Value.Metadata["Owner"] correctly retrieves the metadata. Conversely, when inspecting raw HTTP response headers directly via the Response object, you bypass this parsing step and must query the exact HTTP header name, which is x-ms-meta-owner.
Adım Adım Çözüm
Anahtar Kavram
Understanding how the Azure Blob Storage SDK exposes custom metadata keys vs. how they are represented in raw HTTP response headers.