c# - Azure 存储连接错误(如果系统时间存在差异)

标签 c# azure

我连接到 Windows Phone 8.1 上的 blob azure 存储。如果请求日期~系统时间,则工作正常。但如果手机上的系统日期有差异...例如1 天...然后总是出错...

public static async Task<AzureDownloadResult> DownloadFileFromBlob(string FileName)
{
    using (MemoryStream ms = new MemoryStream())
    {
        try
        {
            CloudBlobContainer container = GetBlobClient.GetContainerReference("data");
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(FileName);
            if (!await blockBlob.ExistsAsync())
            {
                return new AzureDownloadResult(null, AzureDownloadException.NotExists);
            }
            long filesize = blockBlob.Properties.Length;
            await blockBlob.DownloadToStreamAsync(ms.AsOutputStream());
            if (ms.Length != filesize)
            {
                return new AzureDownloadResult(null, AzureDownloadException.Error);
            }
        }
        catch (Exception e)
        {
            //<-error there (if i set random time in phone time settings):
            //message: ...Make sure the value of Authorization header is formed correctly including the signature..
            return new AzureDownloadResult(null, AzureDownloadException.NoneInternetConnectionOrDateTimeError);
        }
        return new AzureDownloadResult(ms.ToArray(), AzureDownloadException.OK);
    }
}

最佳答案

构建所有其他库的 Azure 存储 REST API 使用日期作为请求参数之一,在为请求创建 HMAC 身份验证 token 时提供熵。以下为documented :

The storage services ensure that a request is no older than 15 minutes by the time it reaches the service. This guards against certain security attacks, including replay attacks. When this check fails, the server returns response code 403 (Forbidden).

因此,您应该确保与请求关联的日期时间在该 15 分钟窗口内。

关于c# - Azure 存储连接错误(如果系统时间存在差异),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26704351/

相关文章:

azure - SSL 证书不适用于我的 Azure 应用服务

Spring Batch/Azure 存储帐户 blob 资源 [container"foo", blob ='bar' ] 无法解析为绝对文件路径

.net - Microsoft Azure 存储与 Azure SQL 数据库

sql-server - 将 .bacpac 文件从 v12 Azure SQL 数据库删除/重新导入到同一服务器时,不会导入表

c# - 如何在 sandcaSTLe xml 文档构建中排除不可浏览的成员

C# Strongly Typed Attribute 成员来描述属性

c# - 说明在 foreach 期间更改属性时可枚举的 "unpredictable behavior"

c# - Ajax 发布不工作 MVC 5

c# - Ninject 总是注入(inject) null HttpContext.Current()

azure - 针对多个 Azure 广告对 Web 应用程序进行身份验证?