title: ASP.Net Core 2.2 - Azure SAS Tokens?
body: <p>I am trying to figure out how to generate a time based token for users to access data that is stored in an Azure Storage Account Blob container.  Users upload various data (PDFs, images) but I don't want links to this data to be public.  The recommended strategy was to use a SAS token which I was able to get this working under .Net using the following function which I found on the MS site about a year ago:</p>
  
  <pre><code>        //Function for getting a temporary Azure SAS 
          public static string GetAzureSASToken(string userhashid, int minutes)
          {
  
              //Get Azure SAS Token so we can allow them to temporarily view the photos 
              UploadedFileInfo uploadedfileinfo = new UploadedFileInfo();
  
              //Azure User containter must be all lowercase!!
              uploadedfileinfo.usercontainer = "user-" + userhashid;
              uploadedfileinfo.azureurl = ConfigurationManager.AppSettings["AzureURL"].ToString() + uploadedfileinfo.usercontainer + "/";
  
  
              // Retrieve storage account from connection string.
              string azureconnection = CloudConfigurationManager.GetSetting("StorageConnectionString");
  
              CloudStorageAccount storageAccount = CloudStorageAccount.Parse(azureconnection);
  
              CloudBlobClient client = storageAccount.CreateCloudBlobClient();
              CloudBlobContainer blobContainer = client.GetContainerReference(uploadedfileinfo.usercontainer);
  
              //Set the expiry time and permissions for the container.
              //In this case no start time is specified, so the shared access signature becomes valid immediately.
              SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
              sasConstraints.SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(minutes);
              sasConstraints.Permissions = SharedAccessBlobPermissions.Read;
  
              //Generate the shared access signature on the container, setting the constraints directly on the signature.
              string sasContainerToken = blobContainer.GetSharedAccessSignature(sasConstraints);
  
              return sasContainerToken;
  
          }
  </code></pre>
  
  <p>The problem is that I now need to access these files from an <strong>Asp.Net Core 2.2</strong> app and I can't seem to figure out how to replicate the code to get the token (the Core libraries are different)</p>
  
  <p>Any suggestions on how to accomplish this in .Net Core 2.2?</p>
  
  <p>Thanks!</p>