Windows Azure - Blob 存储初始化 - 授权错误

发布于 2024-10-01 14:12:21 字数 2196 浏览 1 评论 0原文

背景

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

错误

尝试对容器对象进行操作(GetPermissions、Create、如果不存在则创建等)时,出现以下错误:

服务器无法验证请求。确保授权标头的值正确形成,包括签名。

我还尝试使用 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;
        }
    }

Background:

I have an Azure application with one web role which is an ASP.NET application (C#), which uses a charting application to display the results of a calculation. The charting application needs an XML file as input. In order to access this XML file (referenced in the JavaScript), I use XDocument and related classes to manipulate the file, then save it, chart control is loaded on page refresh.

Error:

When trying to operate (GetPermissions, Create, Create if doesn't exist, etc.) on the container object, I get the following error:

Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

I also tried creating the container in advance using SpaceBlock, this didn't seem to have to change the outcome.

Code:

Here is the function I am calling on Page_Load. The error occurs on the line in bold (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;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静水深流 2024-10-08 14:12:21

我在您提供的代码中看不到任何会导致您所讨论的问题的内容。您需要确保在调用权限之前已完成CreateIfNotExist,否则您将收到指定的容器不存在错误(这就是我想要的)猜测您在遇到当前问题之前正在做什么)。

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

I can't see anything in your code that you've provided that would cause the problem you're talking about. You will need to make sure that you've done a CreateIfNotExist before calling the permissions otherwise you will get a The specified container does not exist error (which is what I'm guessing you were doing before you encountered your current problem).

As the code seems fine it's likely to mean that it's something in your environment that's causing you grief, most likely the connection string. I've tried replicating your problem by messing around with the connection string and the only way I've been able to get the exact same error was to use an AccountName with a valid AccountKey from a different account. So my suggestion is to go back to the Azure portal, go to your storage service and copy the Primary Access Key into your cloud config.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文