Azure存储帐户的所有连接字符串似乎只是原始网址+帐户。
有没有办法将连接字符串更改为Azure存储帐户而不是我的CNAME?
编辑:下面的答案很棒,答案发布后几个小时(并勾选)我发现some official documentation on this/the same answer :)
答案 0 :(得分:4)
好问题!我认为你可以,但它只适用于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);
}
}