Dışarıya aktar (0) Yazdır
Tümünü Genişlet
Bu içerik dilinizde bulunmamaktadır ancak İngilizce sürümüne buradan bakabilirsiniz.

Get Storage Account Keys

Updated: March 13, 2015

The Get Storage Keys operation returns the primary and secondary access keys for the specified storage account.

The Get Storage Keys request may be specified as follows. Replace <subscription-id> with your subscription ID, and <service-name> with the name of the storage account.


Method Request URI



You must make sure that the request that is made to the management service is secure. For additional details, see Authenticating Service Management Requests.

The following table describes the request headers.


Request Header Description


Required. Specifies the version of the operation to use for this request. This header should be set to 2009-10-01 or higher. For more information about versioning headers, see Service Management Versioning.

The response includes an HTTP status code, a set of response headers, and a response body.

A successful operation returns status code 200 (OK). For information about status codes, see Service Management Status and Error Codes.

The response for this operation includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.


Response Header Description


A value that uniquely identifies a request made against the management service.

The format of the response body is as follows:

<?xml version="1.0" encoding="utf-8"?>
  <StorageService xmlns="http://schemas.microsoft.com/windowsazure">

The following table describes the elements of the response body.


Element name Description


The Service Management API request URI used to perform Get Storage Account Properties requests against the storage account.


The primary access key for the storage account.


The secondary access key for the storage account.

Use the storage keys returned from the Get Storage Account Keys operation to access the blob, queue, and table service endpoints for the storage.

The following example program takes the subscription ID, an associated management certificate thumbprint, the operation version string, and a storage account name, and prints the returned storage account keys to the console. Initialize the msVersion, subscriptionId, thumbprint and serviceName variables with your own values to run the example code.

using System;
using System.Collections.Generic;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
using System.Xml.Linq;
class Program
    static void Main(string[] args)
        string msVersion = "2011-10-01";
        string subscriptionId = "subscription-id-guid";
        string thumbprint = "certificate-thumbprint";
        string serviceName = "storage-service-name";
            // Obtain the certificate with the specified thumbprint
            X509Certificate2 certificate = GetCertificate(thumbprint);
                subscriptionId, certificate, msVersion, serviceName);
        catch (Exception ex)
            Console.WriteLine("Exception caught in Main:");
    public static X509Certificate2 GetCertificate(string thumbprint)
        List<StoreLocation> locations = new List<StoreLocation> 
            { StoreLocation.CurrentUser, StoreLocation.LocalMachine };
        foreach (var location in locations)
            X509Store store = new X509Store("My", location);
                store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                X509Certificate2Collection certificates =
                        thumbprint, false);
                if (certificates.Count == 1)
                    return certificates[0];
        throw new ArgumentException(string.Format(
            "A certificate with thumbprint '{0}' could not be located.",
    public static void GetStorageAccountKeysExample(
        string subscriptionId,
        X509Certificate2 certificate,
        string version,
        string serviceName)
        string uriFormat = "https://management.core.windows.net/{0}/services/storageservices/{1}/keys";
        Uri uri = new Uri(String.Format(uriFormat, subscriptionId, serviceName));
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
        request.Method = "GET";
        request.Headers.Add("x-ms-version", version);
        request.ContentType = "application/xml";
        XDocument responseBody = null;
        HttpStatusCode statusCode;
        HttpWebResponse response;
            response = (HttpWebResponse)request.GetResponse();
        catch (WebException ex)
            // GetResponse throws a WebException for 400 and 500 status codes
            response = (HttpWebResponse)ex.Response;
        statusCode = response.StatusCode;
        if (response.ContentLength > 0)
            using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                responseBody = XDocument.Load(reader);
        if (statusCode.Equals(HttpStatusCode.OK))
            XNamespace wa = "http://schemas.microsoft.com/windowsazure";
            XElement storageService = responseBody.Element(wa + "StorageService");
                "Storage Account Keys for {0}:{1}{2}",
                serviceName, Environment.NewLine,
            Console.WriteLine("Call to Get Storage Account Keys returned an error:");
            Console.WriteLine("Status Code: {0} ({1}):{2}{3}",
                (int)statusCode, statusCode, Environment.NewLine,

When run, the program output will look something like the following sample:

Storage Account Keys for myexamplestorage1:
<StorageService xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

© 2015 Microsoft