Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 无法在StorageException处理程序中续订Windows Azure SAS密钥_.net_Azure_Exception Handling_Azure Storage_Azure Storage Blobs - Fatal编程技术网

.net 无法在StorageException处理程序中续订Windows Azure SAS密钥

.net 无法在StorageException处理程序中续订Windows Azure SAS密钥,.net,azure,exception-handling,azure-storage,azure-storage-blobs,.net,Azure,Exception Handling,Azure Storage,Azure Storage Blobs,当SAS密钥过期时,我能够从StorageException捕获catch块中的AuthenticationFailed错误代码。然后,我在catch块中对SAS生成方法进行另一次调用,以创建一个新的SAS密钥,该密钥将在稍后过期。当我拥有新的SAS密钥时,我使用它创建另一个CloudBlockBlob对象,以将失败的块写入azure blob。但是,当SAS密钥过期时,我仍然会收到相同的403禁止身份验证错误。为什么在我创建一个新的CloudBlockBlob对象时会发生这种情况,该对象具有不

当SAS密钥过期时,我能够从StorageException捕获catch块中的AuthenticationFailed错误代码。然后,我在catch块中对SAS生成方法进行另一次调用,以创建一个新的SAS密钥,该密钥将在稍后过期。当我拥有新的SAS密钥时,我使用它创建另一个CloudBlockBlob对象,以将失败的块写入azure blob。但是,当SAS密钥过期时,我仍然会收到相同的403禁止身份验证错误。为什么在我创建一个新的CloudBlockBlob对象时会发生这种情况,该对象具有不同的SAS密钥,并且过期时间更长?它与时钟偏移无关,因为我甚至没有在SAS密钥生成中指定StartTime。有什么想法吗?是否有更好的做法来处理SAS续订?谢谢你的帮助!下面是我的代码。注意:我使用javascript来分块上传,因此每次调用WriteBlock方法都是一个全新的状态:

/// Sends the file chunk to the Azure Blob
/// <param name = "BlockId">The id for the current block</param name>
public void WriteBlockToBlob(string BlockId)
{
    try
    {
        Blob = new CloudBlockBlob(new Uri(BlobSasUri));

        Blob.PutBlock(
            BlockId,
            File.InputStream,
            null,
            null,
            uploadBlobOptions,
            null
        );
        /***********************************************************************************************/
        /* REST API Approach */
        //string queryString = (new Uri(abm.BlobContainerSasUri)).Query;
        //abm.BlobContainer = abm.BlobContainerSasUri.Substring(0, abm.BlobContainerSasUri.Length - queryString.Length);
        //string requestUri = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}/{1}{2}&comp=block&blockid={3}",
        //    abm.BlobContainer, abm.FileName, queryString, Convert.ToBase64String(Encoding.UTF8.GetBytes(abm.BlockId)));
        //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
        //request.Method = "PUT";
        //request.ContentLength = abm.File.InputStream.Length;
        //using (Stream requestStream = request.GetRequestStream())
        //{
        //    inputStream.CopyTo(requestStream);
        //}
        //using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
        //{
        //}
        /******************************************************************************************************/
    }
    catch (StorageException stex)
    {
        if (stex.RequestInformation.ExtendedErrorInformation.ErrorCode.Equals("AuthenticationFailed"))
        {
            AzureStorageTester ast = new AzureStorageTester();
            BlobSasUri = ast.getStorageLibrarySas(File.FileName);

            // Retry writing block to blob
            Blob = new CloudBlockBlob(new Uri(BlobSasUri));
            try
            {
                Blob.PutBlock(
                    BlockId,
                    File.InputStream,
                    null,
                    null,
                    uploadBlobOptions,
                    null
                );
            }
            catch (StorageException ex)
            {
                var test = stex.RequestInformation.ExtendedErrorInformation.ErrorCode;
                throw ex;
            }

        }

        //string errMsg = ComposeAndLogStorageException(ExceptionFlag.UploadLargeFileException, stex);
        //BigFileExceptionFlag = "on";
        //throw new ApplicationException(errMsg);
    }
    catch (SystemException se)
    {
        string errMsg = ComposeAndLogSystemException(ExceptionFlag.UploadLargeFileException, se);
        BigFileExceptionFlag = "on";
        throw new ApplicationException(errMsg);
    }
    catch (Exception ex)
    {
        string errMsg = ComposeAndLogException(ExceptionFlag.UploadLargeFileException, ex);
        BigFileExceptionFlag = "on";
        throw new ApplicationException(errMsg);
    }
    finally
    {
        File.InputStream.Close();
    }
}

调试代码正在查看旧异常,而不是新异常

更改此项:

var test = stex.RequestInformation.ExtendedErrorInformation.ErrorCode;
为此:

var test = ex.RequestInformation.ExtendedErrorInformation.ErrorCode;

然后再试一次,看看新的错误代码是什么。

为什么您认为它与时钟偏移无关?你应该通过将开始时间设置为像现在这样的时间-5分钟来排除它。@DavidMakogon:事实上,我就是这么做的。我将开始时间设置为-5分钟。仍然获取相同的AuthenticationFailed错误代码。请发布Blob SAS创建代码段