3

背景

我有一个带有一个 Web 角色的 Azure 应用程序,它是一个 ASP.NET 应用程序 (C#),它使用图表应用程序来显示计算结果。图表应用程序需要一个 XML 文件作为输入。为了访问这个 XML 文件(在 JavaScript 中引用),我使用 XDocument 和相关类来操作文件,然后保存它,在页面刷新时加载图表控件。

错误

尝试对容器对象进行操作(GetPermissions、Create、Create if doesn't exist 等)时,出现以下错误:

服务器未能验证请求。确保 Authorization 标头的值正确形成,包括签名。

我还尝试使用 SpaceBlock 提前创建容器,这似乎不必改变结果。

代码

这是我在 Page_Load 上调用的函数。错误出现在粗体 (GetPermissions) 行:

    private void InitializeStorage()
    {
        if (storageInitialized)
        {
            return;
        }

        lock (gate)
        {
            if (storageInitialized)
            {
                return;
            }

            try
            {
                CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
                {
                    configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
                });

                // read account configuration settings
                var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

                // create blob container for images
                blobStorage = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer container = blobStorage.GetContainerReference("xml");

                // configure container for public access
                **var permissions = container.GetPermissions();**
                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                container.SetPermissions(permissions);

                CloudBlob opcBlob = container.GetBlobReference("OptionPriceChart.xml");
                opcBlob.DownloadToFile("opcLocal.xml");

            }
            catch (WebException)
            {
                throw new WebException("Storage services initialization failure. "
                    + "Check your storage account configuration settings. If running locally, "
                    + "ensure that the Development Storage service is running.");
            }

            storageInitialized = true;
        }
    }
4

1 回答 1

1

我在您提供的代码中看不到任何会导致您正在谈论的问题的内容。您需要确保CreateIfNotExist在调用权限之前已经完成了操作,否则您会收到The specified container does not exist错误消息(我猜您在遇到当前问题之前正在这样做)。

由于代码看起来不错,这可能意味着您的环境中的某些东西让您感到悲伤,很可能是连接字符串。我已经尝试通过弄乱连接字符串来复制您的问题,而我能够得到完全相同的错误的唯一方法是将 an与来自不同帐户AccountName的有效帐户一起使用。AccountKey所以我的建议是返回 Azure 门户,转到您的存储服务并将主访问密钥复制到您的云配置中。

于 2010-11-09T20:42:12.517 回答