来自WindowsAzure.Storage的生产中出现403错误

Bri*_*Kay 12 vb.net asp.net azure azure-storage-blobs

我有一个使用WindowsAzure.Storage API v3的WebForms应用程序.它在开发和一个生产环境中工作正常,但我推出了一个新实例,任何调用Azure Blob存储的代码都会给我403错误.

我已经习惯了这一段时间了,并且它对Blob存储的任何调用失败了,所以不是显示我的代码,而是显示我的堆栈跟踪:

[WebException: The remote server returned an error: (403) Forbidden.]
   System.Net.HttpWebRequest.GetResponse() +8525404
   Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) +1541

[StorageException: The remote server returned an error: (403) Forbidden.]
   Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) +2996
   Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExists(BlobContainerPublicAccessType accessType, BlobRequestOptions requestOptions, OperationContext operationContext) +177
   ObsidianData.Azure.Storage.GetContainer(CloudBlobClient client, Containers targetContainer) in D:\Dev\nSource\Obsidian\Source\ObsidianData\Azure\Storage.vb:84
   ObsidianWeb.Leads.HandleListenLink(String fileName, HyperLink link) in D:\Dev\nSource\Obsidian\Source\ObsidianWeb\Bdc\Leads.aspx.vb:188
   ObsidianWeb.Leads.LoadEntity_ContactDetails(BoLead lead) in D:\Dev\nSource\Obsidian\Source\ObsidianWeb\Bdc\Leads.aspx.vb:147
   ObsidianWeb.Leads.LoadEntity(BoLead Lead) in D:\Dev\nSource\Obsidian\Source\ObsidianWeb\Bdc\Leads.aspx.vb:62
   EntityPages.EntityPage`1.LoadEntity() +91
   EntityPages.EntityPage`1.Page_LoadComplete(Object sender, EventArgs e) +151
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4018
Run Code Online (Sandbox Code Playgroud)

这是我试过的......

  • 在此环境中失败的AzureStorageConnectionString肯定适用于生产
  • 其他连接字符串(来自其他生产环境,其工作)也在这里获得403
  • 在一些旧版本的REST api中我似乎存在时间戳的问题(我没有直接使用它......)所以我确定时间是正确的,甚至尝试将服务器切换到UTC时间.
  • 尝试切换http/https之间的连接字符串.
  • 升级到最新版本的API(v3.1)
  • 试图摆弄代码以确保每次调用Azure存储都获得403.确实如此.
  • 无奈之下,在服务器上安装Azure Powershell只是为了验证与Azure的某种通信是否正常工作.这很好.
  • 浏览到天蓝色的管理门户网站也很好.

有任何想法吗?这应该只是使用端口80或443,对吗?所以这不应该是某种网络问题.如果那是错的,请告诉我.

  • 工作生产计算机是Azure VM(带有IIS 7.5的Server 2008 R2)与服务器也存在一些差异:
  • 这台新机器是物理硬件(Server 2012和IIS 8)
  • 这是在我的azure订阅中使用不同的存储帐户,但是我已经尝试了总共3个连接字符串,但这些都没有在这里工作.

更新:有人要求查看代码.好的,我写了一个名为Azure.Storage的类,它只是抽象我的云存储代码.我们没有调用Storage.Exists,所以这里是感觉相关的那个类的一部分:

    Public Shared Function Exists(container As Containers, blobName As String) As Boolean
        Dim Dir As CloudBlobContainer = GetContainer(container)
        Dim Blob As CloudBlockBlob = Dir.GetBlockBlobReference(blobName.ToLower())

        Return Blob.Exists()
    End Function

    Private Shared Function GetContainer(client As CloudBlobClient, targetContainer As Containers)
        Dim Container As CloudBlobContainer = client.GetContainerReference(targetContainer.ToString.ToLower())
        Container.CreateIfNotExists()
        Container.SetPermissions(New BlobContainerPermissions() With {.PublicAccess = BlobContainerPublicAccessType.Blob})

        Return Container
    End Function

    Private Shared Function GetCloudBlobClient() As CloudBlobClient
        Dim Account As CloudStorageAccount = CloudStorageAccount.Parse(Settings.Cloud.AzureStorageConnectionString())

        Return Account.CreateCloudBlobClient()
    End Function
Run Code Online (Sandbox Code Playgroud)

... 容器只是一个容器名称的枚举(有几个):

 Public Enum Containers
     CallerWavs
     CampaignImports
     Delve
     Exports
     CampaignImages
     Logos
     ReportLogos
     WebLinkImages
 End Enum
Run Code Online (Sandbox Code Playgroud)

......是的,他们有大写字符,这会导致问题.在它熄灭之前,所有东西都被迫小写.

此外,我确实验证了正确的AzureConnectionString来自我的设置类.再一次,我尝试了一些在别处工作的东西.而这个也适用于其他地方!

Gau*_*tri 19

请检查有问题的服务器上的时钟.除了错误的帐户密钥,如果服务器上的时间与存储服务器上的时间不同,您还可能会收到403错误(允许或允许+/- 15分钟的偏差).

  • 天哪,我差点疯了.这太愚蠢了.为什么它在时间上应该返回403,为什么不至少提供一个有意义的消息,如"你的请求时间不能被接受". (5认同)