简体   繁体   English

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

[英]Windows Azure - Blob storage initialization - Authorization Error

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. 我有一个Azure应用程序,其中一个Web角色是一个ASP.NET应用程序(C#),它使用图表应用程序来显示计算结果。 The charting application needs an XML file as input. 图表应用程序需要XML文件作为输入。 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. 为了访问这个XML文件(在JavaScript中引用),我使用XDocument和相关类来操作文件,然后保存它,在页面刷新时加载图表控件。

Error : 错误

When trying to operate (GetPermissions, Create, Create if doesn't exist, etc.) on the container object, I get the following error: 当试图在容器对象上操作(GetPermissions,Create,Create if not exists等)时,我收到以下错误:

Server failed to authenticate the request. 服务器无法验证请求。 Make sure the value of Authorization header is formed correctly including the signature. 确保正确形成Authorization标头的值,包括签名。

I also tried creating the container in advance using SpaceBlock, this didn't seem to have to change the outcome. 我也尝试使用SpaceBlock提前创建容器,这似乎不一定要改变结果。

Code : 代码

Here is the function I am calling on Page_Load. 这是我在Page_Load上调用的函数。 The error occurs on the line in bold (GetPermissions): 该行以粗体显示错误(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;
        }
    }

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). 您需要确保在调用权限之前已经完成了CreateIfNotExist ,否则您将得到一个The specified container does not exist错误(这是我猜你在遇到当前问题之前所做的)。

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. 我已经尝试通过弄乱连接字符串来复制您的问题,我唯一能够得到完全相同的错误的方法是使用具有来自不同帐户的有效AccountKeyAccountName 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. 所以我的建议是返回Azure门户,转到存储服务并将主访问密钥复制到您的云配置中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM