2

I am working with SharePoint 2010 with Client Side Object Model (C#).

I am able to login in Browser but with the same credential I am not able to login with CSOM C# Code.

I am getting

401 Unauthorized Access

What should be possible reason I need to verify?

What I tried:-

  • I tried supplying clientContext.AuthenticationMode = ClientAuthenticationMode.Default;. Still the issue is same. I can confirm that the site does not uses Form Based Authentication.

Please provide your valuable suggestions.

1
  • 1
    you can try $clientContext.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials Aug 3 '16 at 12:36
2

Try using following code:

clientContext clientContext = new clientContext(siteUrl);
CredentialCache myCache = new CredentialCache();
myCache.Add(new Uri(siteUrl), "Your Authentication Type", new NetworkCredential(userName, password));
clientContext.Credentials = myCache;

Please let me know if it works.

1
  • 1
    I It worked. I used "NTLM" at the place of "Your Authentication Type" :-) Aug 3 '16 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.