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.

Aakash Maurya
  • 8,481
  • 4
  • 42
  • 74

1 Answers1

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.

Codec
  • 1,340
  • 1
  • 11
  • 24