Could not upload to the storage location the remote server returned an error 403 forbidden?

Error: Exception calling “ExecuteQuery” with “0” argument(s): “The remote server returned an error: (403) Forbidden.” in PowerShell scripts for SharePoint Online.

Could not upload to the storage location the remote server returned an error 403 forbidden?

Follow this checklist to resolve Executequery 403 forbidden error in SharePoint Online PowerShell:

  1. You may have provided the credentials of another tenant, which would end up with this error message (Happens when working with multiple tenants!) So make sure the URL and credentials are correct.
  2. You may be missing the SharePoint Online Client Component SDK on your client computer. Make sure you have the latest version installed and the referenced DLL paths are correct.
  3. You may be attempting to access a site that you don’t have access to! Verify your access to the site by browsing to it. Having Tenant Admin or SharePoint Online Administrator roles doesn’t gain your access to SharePoint sites automatically. You have to add yourself to the site explicitly: How to Add Site collection Administrator to SharePoint Online using PowerShell?
  4. The site may be in locked state! You can check the lock status and unlock: How to Lock/Unlock Sites in SharePoint Online?
  5. You may need to be in your organization network with a compliant device as per the conditional access policies of your tenant.
  6. The credential you pass must be of type “SharePointOnlineCredentials”. E.g.,

#Load SharePoint CSOM Assemblies Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" #parameters $SiteURL = "https://Crescent.sharepoint.com" $UserName = "[email protected]" $Password = "Password goes here" $SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force #Setup the Context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword) $Ctx.Credentials = $Cred #Get the Site Collection storage used $Site = $Ctx.Site $Ctx.Load($Site) $Site.Retrieve("Usage") $ctx.ExecuteQuery() $StorageUsed = [Math]::Round(($Site.Usage.Storage/1MB),2) #Get Site Collection Size Write-host "Storage Used: $StorageUsed MB"

  1. If you try to connect to the Tenant Admin site, make sure the Tenant Admin URL is: https://YourDomain-admin.sharepoint.com, The below script would give you an error: Get-PnPSite : The remote server returned an error: (403) Forbidden.

$TenantAdminURL = "https://crescent-admin.sharepoint.com/sites/london" #Connect to the Site Connect-PnPOnline -URL $TenantAdminURL -Interactive Get-PnPSite

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

I am getting the following error when trying to upload files to the Azure blob storage. This was working fine before. Does anyone know why it would return a 403 Forbidden message? I am using C# in ASP.NET MVC and have installed the client library for Windows Azure Storage.

[WebException: The remote server returned an error: (403) Forbidden.] System.Net.HttpWebRequest.GetResponse() +1322 Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) +1144

[StorageException: The remote server returned an error: (403) Forbidden.] Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand1 cmd, IRetryPolicy policy, OperationContext operationContext) +4529 Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStreamHelper(Stream source, Nullable1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) +1303 Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream(Stream source, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) +29 Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromFile(String path, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) +84

asked Aug 3, 2017 at 18:51

Prithvi RamanaPrithvi Ramana

2011 gold badge4 silver badges12 bronze badges

3

According to the 403 exception, it seems that you have no access to the container.

This was working fine before

If you are using Azure storage account key to access the resource, please have a try to make sure that account key is not changed or you could regenerate it and try it again.

If you are using Service SAS, please have a try to make sure that it is not out of date. You also could use Azure portal or Microsoft Azure Storage Explorer to regenerate SAS token and try it again.

Update:

According to the comment:

Azure storage also support CORS, more detail please refer to document. We also could set CORS from azure portal, please refer to the screenshot.

Could not upload to the storage location the remote server returned an error 403 forbidden?

answered Aug 4, 2017 at 1:20

Tom Sun - MSFTTom Sun - MSFT

23.4k3 gold badges26 silver badges43 bronze badges

7

Not the answer you're looking for? Browse other questions tagged c# asp.net-mvc azure azure-storage azure-blob-storage or ask your own question.

How do I fix the remote server returned an error 403 Forbidden?

This problem usually happens when the computer is using the Proxy/VPN. Please disable the Proxy/VPN temporary and try again. If you're using the Proxy Settings in Driver Easy, please go to the Settings panel and set it to Use default browser settings.

Why does one drive say 403 Forbidden?

The “403 Forbidden” error might occur because of one of the following conditions: Your browser cache has to be cleared. Your permissions to the file haven't replicated correctly on the server. Your OneDrive site is locked.