小智 10
请注意这一点,因为它是谷歌的热门产品,信息不再是最新信息.
您可以CloudStorageAccount通过传递给的连接字符串进行配置FromConfigurationSetting().
您可以在下面构建一个配置字符串:https: //docs.microsoft.com/en-gb/azure/storage/common/storage-configure-connection-string
如果右键单击角色,IDE中还有一个帮助器.
Ogg*_*las 10
Microsoft 有一个很好的指南,名为“将应用程序连接到 Azure 存储”,其中涵盖了您所需的一切。
描述:
创建一个简单的应用程序并添加配置、客户端库引用和代码以将其连接到 Azure 存储。
https://learn.microsoft.com/en-us/learn/modules/connect-an-app-to-azure-storage/
步骤 7 连接到您的 Azure 存储帐户
连接字符串示例:
DefaultEndpointsProtocol=https;AccountName={your-storage};
AccountKey={your-access-key};
EndpointSuffix=core.windows.net
Run Code Online (Sandbox Code Playgroud)
REST 端点是存储帐户名称、数据类型和已知域的组合。例如:
| 数据类型 | 端点示例 |
|---|---|
| 斑点 | https://[名称].blob.core.windows.net/ |
| 队列 | https://[名称].queue.core.windows.net/ |
| 桌子 | https://[名称].table.core.windows.net/ |
| 文件 | https://[名称].file.core.windows.net/ |
为了获取连接字符串,我通常遵循 @user3459730 示例并从 Azure 门户复制它。转到存储帐户 -> 访问密钥,单击显示密钥并复制连接字符串。
小智 9
参考:Azure 文档
Azure 存储帐户的连接字符串:
DefaultEndpointsProtocol=[http|https];AccountName=myAccountName;AccountKey=myAccountKey
例子:
DefaultEndpointsProtocol=https;AccountName=storagesample;AccountKey=<account-key>
Run Code Online (Sandbox Code Playgroud)
到存储模拟器的连接字符串:
配置文件
<appSettings>
<add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
</appSettings>
DefaultEndpointsProtocol=http;AccountName=testacc1;
AccountKey=1gy3lpE7Du1j5ljKiupgKzywSw2isjsdfdsfsdfsdsgfsgfdgfdgfd/YThisv/OVVLfIOv9kQ==;
BlobEndpoint=http://127.0.0.1:8440/testacc1;
TableEndpoint=http://127.0.0.1:8440/testacc1;
QueueEndpoint=http://127.0.0.1:8440/testacc1;
Run Code Online (Sandbox Code Playgroud)
前任:
<connectionStrings>
<add name="AzureStorageAccount" connectionString="DefaultEndpointsProtocol=https;AccountName=testdata;Accoun??tKey=1gy3lpE7Du1j5ljKiupgKzywSw2isjsdfdsfsdfsdsgfsgfdgfdgfd/YThisv/OVVLfIOv9kQ==;"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
但有时它不起作用并且会通过错误
An unhandled exception of type 'System.FormatException' occurred in Microsoft.WindowsAzure.Storage.dll
Additional information: No valid combination of account information found.
Run Code Online (Sandbox Code Playgroud)
那么请尝试使用以下代码:已测试且工作 100%
var accountName = "test2rdsfdg462";
var keyValue = "1gy3lpE7Du1j5ljKiupgKzywSfsdfdsfsdfsdfsdfsdfsdqGxd7/YThisv/OVVLfIOv9kQ==";
var useHttps = true;
var connValid = true;
var storageCredentials = new StorageCredentials(accountName, keyValue);
var storageAccount = new CloudStorageAccount(storageCredentials, useHttps);
var conString = storageAccount.ToString(connValid);
CloudStorageAccount sa = CloudStorageAccount.Parse(connString);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22631 次 |
| 最近记录: |