我有一个Azure功能,该功能应处理存储帐户容器中的文件。应该每天触发Azure功能。但是每周一次或两次,我看到容器中的某些文件未得到处理:(由于错误403,开始时未处理600个文件中的401个文件)
正如我在Stackoverflow中阅读的。这是因为SAS令牌时间偏斜。我的代码没有大的改动就可以解决这个问题吗?
我的代码:
CloudStorageAccount sa;
CloudStorageAccount.TryParse("MyConnString", out sa);
_blobClient = sa.CreateCloudBlobClient();
ICloudBlob sourceBlob = _blobClient.GetBlobReferenceFromServer(new Uri(BlobUrl));
更新
执行功能时出现消息异常: process_files_by_http_trigger_activity远程服务器返回了一个 错误:(403)禁止。远程服务器返回错误:(403) 禁止。
调用堆栈:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException:在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor + d__16.MoveNext (Microsoft.Azure.WebJobs.Host,版本= 2.4.0.0,文化=中性, PublicKeyToken = 31bfxxxx64e35) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor + d__13.MoveNext (Microsoft.Azure.WebJobs.Host,版本= 2.4.0.0,文化=中性, PublicKeyToken = 31bfxxxx64e35)内部异常 Microsoft.WindowsAzure.Storage.StorageException在以下位置处理 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw:在 Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync (Microsoft.WindowsAzure.Storage,版本= 7.2.1.0,文化=中性, PublicKeyToken = 31bfxxxx64e35Microsoft.WindowsAzure.Storage, 版本= 7.2.1.0,文化=中性,PublicKeyToken = 31bfxxxx64e35: c:\ Program档案 (x86)\ Jenkins \ workspace \ release_dotnet_master \ Lib \ ClassLibraryCommon \ Core \ Executor \ Executor.csMicrosoft.WindowsAzure.Storage, 版本= 7.2.1.0,文化=中性,PublicKeyToken = 31bfxxxx64e35: 604)在 Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer (Microsoft.WindowsAzure.Storage,版本= 7.2.1.0,文化=中性, PublicKeyToken = 31bfxxxx64e35Microsoft.WindowsAzure.Storage, 版本= 7.2.1.0,文化=中性,PublicKeyToken = 31bfxxxx64e35: c:\ Program档案 (x86)\ Jenkins \ workspace \ release_dotnet_master \ Lib \ ClassLibraryCommon \ Blob \ CloudBlobClient.csMicrosoft.WindowsAzure.Storage, 版本= 7.2.1.0,文化=中性,PublicKeyToken = 31bfxxxx64e35: 563)在 Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer (Microsoft.WindowsAzure.Storage,版本= 7.2.1.0,文化=中性, PublicKeyToken = 31bfxxxx64e35Microsoft.WindowsAzure.Storage, 版本= 7.2.1.0,文化=中性,PublicKeyToken = 31bfxxxx64e35: c:\ Program档案 (x86)\ Jenkins \ workspace \ release_dotnet_master \ Lib \ ClassLibraryCommon \ Blob \ CloudBlobClient.csMicrosoft.WindowsAzure.Storage, 版本= 7.2.1.0,文化=中性,PublicKeyToken = 31bfxxxx64e35: 546)在 bip.dev.afu.inbound.we.process_xz_files_by_http_trigger.XzFileMove (bip.dev.afu.inbound.we,Version = 1.0.0.0,Culture = neutral, PublicKeyToken = null) bip.dev.afu.inbound.we.process_xz_files_by_http_trigger + d__10.MoveNext (bip.dev.afu.inbound.we,Version = 1.0.0.0,Culture = neutral, PublicKeyToken = null) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker
2+<InvokeAsync>d__2.MoveNext (Microsoft.Azure.WebJobs.Host, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bfxxxx64e35) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b7xxxx934e089) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b7xxxx934e089) at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker
2 + d__9.MoveNext (Microsoft.Azure.WebJobs.Host,版本= 2.4.0.0,文化=中性, PublicKeyToken = 31bfxxxx64e35) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor + d__24.MoveNext (Microsoft.Azure.WebJobs.Host,版本= 2.4.0.0,文化=中性, PublicKeyToken = 31bfxxxx64e35) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor + d__23.MoveNext (Microsoft.Azure.WebJobs.Host,版本= 2.4.0.0,文化=中性, PublicKeyToken = 31bfxxxx64e35) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor + d__22.MoveNext (Microsoft.Azure.WebJobs.Host,版本= 2.4.0.0,文化=中性, PublicKeyToken = 31bfxxxx64e35) System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (mscorlib,版本= 4.0.0.0,文化=中性, PublicKeyToken = b7xxxx934e089) System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(mscorlib, 版本= 4.0.0.0,文化=中性,PublicKeyToken = b7xxxx934e089)
在 Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor + d__16.MoveNext (Microsoft.Azure.WebJobs.Host,版本= 2.4.0.0,文化=中性, PublicKeyToken = 31bfxxxx64e35)内部异常 System.Net.WebException处理 Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync:
在System.Net.HttpWebRequest.GetResponse(System,Version = 4.0.0.0, 文化=中立,PublicKeyToken = b7xxxx934e089) Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync (Microsoft.WindowsAzure.Storage,版本= 7.2.1.0,文化=中性, PublicKeyToken = 31bfxxxx64e35Microsoft.WindowsAzure.Storage, 版本= 7.2.1.0,文化=中性,PublicKeyToken = 31bfxxxx64e35: c:\ Program档案 (x86)\ Jenkins \ workspace \ release_dotnet_master \ Lib \ ClassLibraryCommon \ Core \ Executor \ Executor.csMicrosoft.WindowsAzure.Storage, 版本= 7.2.1.0,文化=中性,PublicKeyToken = 3xxxxx6ad364e35: 677)
答案 0 :(得分:0)
从基础开始,Azure存储连接字符串使用以下格式。请确保您为连接字符串提供了正确的帐户名和密钥对。如果您设置帐户n1和帐户n2的帐户密钥,则会导致异常。
DefaultEndpointsProtocol=https;AccountName=[accountName];AccountKey=[accountKey];EndpointSuffix=core.windows.net
我建议您打印您的连接字符串,看看它是否一直与您在App.setting中提到的相同。
Trace.Write(ConnectionString);
请确保您的系统/应用程序实例的当前日期时间正确。
存储服务确保请求在到达服务之前不超过15分钟。这可以防止某些安全攻击,包括重放攻击。如果此检查失败,服务器将返回响应代码403(禁止)。
希望它会有所帮助。随时在对话中为我添加标签,以获取其他帮助。