作者:悠哉游_甘肃 | 来源:互联网 | 2023-02-01 22:31
在尝试从azure blob存储中访问文件时,我的测试站点在部署开始后被禁止403.这只是我们测试环境中的一个问题,新版本在生产中运行良好.生产和测试都托管在azure中,并且都使用自己的azure blob存储.
我已经尝试重新生成blob存储的访问密钥,没有任何运气.
我可以在本地使用访问密钥并连接到测试blob存储并访问文件就好了.
如果我尝试更改测试环境以使用生产blob存储,我仍然会收到403禁止错误.
Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (403) Forbidden. ---> System.Net.WebException: The remote server returned an error: (403) Forbidden. at System.Net.HttpWebRequest.GetResponse() at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 677 --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand
1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 604 at Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer(StorageUri blobUri, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlobClient.cs:line 563 at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.GetBlobReferenceFromServer(String blobName, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Blob\CloudBlobContainer.cs:line 818 at ASP.XYZ in d:\XYZ.cshtml:line 27 Request Information RequestID:fc137321-0001-00ce-02d2-de5736000000 RequestDate:Tue, 06 Jun 2017 14:41:21 GMT StatusMessage:Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
它必须是运行测试站点的azure app服务的问题.我只是看不出它会是什么.
请参阅这里的一些非常简单的代码https://gist.github.com/Skaanning/5cddf95a0d1ff210482d99a683e0be9c.
编辑
我有多个其他blob存储,但它们都不在测试站点上工作.但它们在其他环境中工作正常.
1> Amor..:
var img = container.GetBlobReference("someimage.png"); //这很好用
var img2 = container.GetBlobReferenceFromServer("someimage.png"); //这会抛出403
第一行将正常工作.原因是当我们执行GetBlobReference方法时它不会向服务器发送请求.执行GetBlobReferenceFromServer方法时,它会向服务器发送请求以获取blob内容.如果在blob服务器中找不到blob,它将抛出404未找到的异常.
在尝试从azure blob存储中访问文件时,我的测试站点在部署开始后被禁止403.
使用经常由错误的访问密钥引起的403禁止异常.请打印出测试环境中使用的连接字符串.
Trace.Write(CloudConfigurationManager.GetSetting("blob.storage"));
Azure存储连接字符串使用以下格式.请确保您为连接字符串提供了正确的帐户名称和密钥对.如果为帐户名2设置帐户名1和帐户密钥,则会导致异常.
DefaultEndpointsProtocol=https;AccountName=[accountName];AccountKey=[accountKey];EndpointSuffix=core.windows.net
另一件事会导致此问题是您的存储服务器的请求被测试服务器拒绝.请检查您是否在web.config中配置了动态IP安全性.
编辑2017/6/7 4:26 PM
我建议你接受我的建议.请在运行时打印出连接字符串.如果在Azure门户和web.config中的应用程序设置中设置连接字符串.Azure门户中的设置将覆盖web.config中的设置.
还请在运行时打印出当前日期时间,以检查应用程序实例的系统时间是否正确.如果系统的日期或时间已更改,404 Forbidden也将发生.
存储服务确保请求在到达服务时不超过15分钟.这可以防范某些安全攻击,包括重放攻击.当此检查失败时,服务器返回响应代码403(禁止).
参考:Azure存储服务的身份验证
编辑2017/6/7 5:55 PM
在部署发行版时,您是否尝试删除测试服务器上的所有原始文件?
我试着上下缩放,没有任何运气.但后来我尝试从32位更改为64位,现在它可以正常工作!我将保持这个问题,以防有人能解释这里发生的事情