Unable to set public file url expiry to more than 1 year for Azure cloud storage accounts in c# code

93 Views Asked by At

Trying to create a shared access signature (SAS) Uri for a file which in azure storage accounts. But getting an error when we set expiry to 10000 years Error: The added or subtracted value results in an un-representable DateTime

Is this not possible? Please help.

BlobSasBuilder sasBuilder = new BlobSasBuilder()
{             
   sasBuilder.ExpiresOn = DateTimeOffset.UtcNow.AddYears(10000);
}
1

There are 1 best solutions below

0
Roe On

I'm pretty sure 23:59:59.9999999 UTC, December 31, 9999 is the maximum date allowed by a DateTime. Consider using DateTime.MaxValue or adding less total years. My preference would be the built in MaxDate this way you never run into the same issue again

To my knowledge it is not a valid BlobSasBuilder object if you leave out the expiration date. So sadly you cannot simply leave the field empty