Forum Discussion
CSOM : Server Unauthorized Access Exception: Access Denied.
- Aug 18, 2017
My suggestion, you're using SharePoint On-Premises.
For On-Premises credentials should be defined in the following way:
using System.Net; using Microsoft.SharePoint.Client; using (ClientContext context = new ClientContext("http://sp-onprem/")) { context.Credentials = new NetworkCredential("user", "password", "domain"); // CSOM code }
SharePoint Online requires the secure string as a password:
using (ClientContext context = new ClientContext("https://contoso.sharepoint.com/")) { string pwd = "password"; SecureString password = new SecureString(); foreach (char c in pwd.ToCharArray()) { password.AppendChar(c); } context.Credentials = new SharePointOnlineCredentials("user", password); // CSOM code }
Also, I would recommend to figure out what auth scenario your instance is configured to support.
My suggestion, you're using SharePoint On-Premises.
For On-Premises credentials should be defined in the following way:
using System.Net; using Microsoft.SharePoint.Client; using (ClientContext context = new ClientContext("http://sp-onprem/")) { context.Credentials = new NetworkCredential("user", "password", "domain"); // CSOM code }
SharePoint Online requires the secure string as a password:
using (ClientContext context = new ClientContext("https://contoso.sharepoint.com/")) { string pwd = "password"; SecureString password = new SecureString(); foreach (char c in pwd.ToCharArray()) { password.AppendChar(c); } context.Credentials = new SharePointOnlineCredentials("user", password); // CSOM code }
Also, I would recommend to figure out what auth scenario your instance is configured to support.
This is what i do before, but the error show (access denied). Actually this error is shown for the local user that don't have the authorization to access the sharepoint subsite.
- Aug 21, 2017
Oh, so your user account has no permissions?
You should use an account with permissions corresponding to operations which should be done with in CSOM for sure.
- amir asyrafAug 22, 2017Copper Contributor
that's what i think, let say i need to install for 10k user PC.. and the PC information need to be send to the sharepoint datalist, it will not that i gonna give permission to them right ?. Any other idea ?
- Aug 21, 2017
Are you sure you fixed your code with providing credentials to clientContext (`clientContext.Credentials = ...`)?
In your code sample, there is no such a string. That means that:
- In a domain network, context belongs to a user who executes the process;
- Outside a domain, no credentials passed at all.
As a result, you get 401 Unauthorized.
If you provide clientContext.Credentials, please make sure:
- User/pass/domain are correct
- You can login with the user in UI
- SharePoint tenant is configured for the authentication type you're trying
- DeletedAug 21, 2017
Ok so you want to have elevated privileges?
That is not possible using Csom.
- amir asyrafAug 22, 2017Copper Contributor
i see, so the conclusion is.. i need to give them permission at sharepoint so that they can send the data to sharepoint datalist ?
- DeletedAug 22, 2017
The only thing you could do is write full trust code which populates the list. or build a webservice which has the rights.