【问题标题】:How to provide an Azure Storage CNAME as part of the connection string?如何提供 Azure 存储 CNAME 作为连接字符串的一部分?
【发布时间】:2018-01-03 05:21:17
【问题描述】:

Azure 存储帐户的所有连接字符串似乎只是原始 url + 帐户。

有没有办法将 Azure 存储帐户的连接字符串改为我的 CNAME?

编辑:下面的答案很棒,在答案发布(并打勾)几个小时后,我找到了some official documentation on this/the same answer :)

【问题讨论】:

    标签: azure azure-storage


    【解决方案1】:

    好问题!我认为您可以,但它只能与Blob Storage 一起使用,因为您只能为 blob 端点指定 CNAME 映射,而且您需要在某处使用您的帐户名,因为它用于授权标头计算。我就是这样做的:

        static void ConnectViaCname()
        {
            var cred = new StorageCredentials("account-name", "account-key");
            var account = new CloudStorageAccount(cred, new Uri("https://cnamemapping.com"), null, null, null);
            var client = account.CreateCloudBlobClient();
            var containers = client.ListContainers();
            foreach (var container in containers)
            {
                Console.WriteLine(container.Uri.AbsoluteUri);
            }
        }
    

    更新

    如果您想使用连接字符串,请以这种格式指定连接字符串:

    DefaultEndpointsProtocol=https;
    BlobEndpoint=https://cnamemapping.com;
    AccountName=account-name;
    AccountKey=account-key
    

    所以代码是:

        static void ConnectViaCname()
        {
            var connectionString = "DefaultEndpointsProtocol=https;BlobEndpoint=https://cnamemapping.com;AccountName=account-name;AccountKey=account-key";
            var account = CloudStorageAccount.Parse(connectionString);
            var client = account.CreateCloudBlobClient();
            var containers = client.ListContainers();
            foreach (var container in containers)
            {
                Console.WriteLine(container.Uri.AbsoluteUri);
            }
        }
    

    【讨论】:

    • 用羽毛把我吹倒!这样可行!!楼主你厉害旁注:DefaultEndpointsProtocol=https :) :) 请始终确保安全!
    • 关于https,完全同意。只是当不支持 https 时,我有一个非常旧的 CNAME 映射帐户。这就是为什么我使用 http 来确保一切正常。我将编辑我的问题并将其更改为 https。
    • 提醒@gauravmantri - 官方文档也提到了这一点!我刚刚找到它:P docs.microsoft.com/en-us/azure/storage/common/…
    • :)。这是关于 HTTPS 的吗?出于某种原因,我认为它现在受支持(但我可能错了)。
    • 不。这是关于官方文档实际上如何准确地提及您的答案。意思是,我应该先检查那里。 (嗯,我做到了......当我浏览该页面并正在阅读关于存储 CNames 的另一页根本没有提到这一点时,我只是错过了该部分)。
    猜你喜欢
    • 2019-11-17
    • 2015-12-02
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多