I am using Client Object Model to access a document library on a VM SharePoint server where I do have 'FullControl' access to a Site & Site collection.

The below code works on my SharePoint Foundation environment installed on my machine, but not on the network SharePoint Server (HTTP 500 error).

  ClientContext clientContext = new ClientContext(siteUrl);
  Web site = clientContext.Web;

So, I have tried using

  System.Net.CredentialCache cc = new System.Net.CredentialCache();
  NetworkCredential nc = new NetworkCredential("uName","pwd", "domain");

Using the above code gives HTTP 401 unauthorized error.

I go to the site and see my name on the site with Full Control. How to resolve this?

1 Answer 1


There can be many reasons why you are receiving 401 and it really depends on how your 'network SP server' is set and mainly what kind of authorization it is using.

Before proceeding first verify that your username, password and domain are correct (and then double check it).

You can also check this similar question: HTTP 401, Unauthorized using the Managed Client Object Model

If you are using FBA (Forms Based Authentication) you need to specify your credentials as follows:

ClientContext ctx = new ClientContext(someSiteUrl); 
ctx.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication; 
ctx.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo(myUserName, myUserPwd);

Using the Client Object Model with a Forms Based Auth Site in SharePoint 2010

And if you are using mixed authentication (Windows & FBA) then you need also to apply a little 'hack':

clientContext.ExecutingWebRequest += new EventHandler(clientContext_ExecutingWebRequest);

static void clientContext_ExecutingWebRequest(object sender, WebRequestEventArgs e)
  e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");

Accessing mixed authentication web app with Client Object Model and Web Serices

  • clientContext.Credentials = CredentialCache.DefaultNetworkCredentials; worked for me.
    – Yalaman
    Apr 11, 2012 at 18:46
  • @Yalaman - great! You should upvote linked answer (that I provided) if it was helpfull. You should also consider accepting/upvoting my answer or you can even add your own solution to this problem and then accept it. By doing so you can help someone else facing same issue. Apr 11, 2012 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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