I try to access a SharePoint 2013 Server via C# CSOM.

The only thing I do is create the ClientContext, set the context.Credentials to my NetworkCredential, and ask for the Web Web web = context.Web;.

After context.ExecuteQuery(); I get an 401 Unauthorized Error/Exception.

After playing around (with another server used for testing) I realized, that the problem is not due to incorrect password or incorrect credentials or even incorrect access rights (I'm Admin), but because of the server itself.

I know for sure:

  • My Credentials work fine (I can login via Web Interface as well)
  • The problem is from the server, not from the client
  • On my test environment it works!

A small background info.

The System that gives me the error had an issue last week and went completely offline the whole last week. After a lot of time, the Admins got it back to work again.

I assume, that a feature or something on the system did not start properly after the issues, and that's why I can't access it via CSOM.

My question is:
What SharePoint Feature or other Service needs to run on a SharePoint Server, so you can access it via CSOM.

My source code:

.ServerCertificateValidationCallback +=
(sender, cert, chain, sslPolicyErrors) => true; //used for https to work properly

string spurl = "https://my.spserver.com/sites/mysite";
using (ClientContext context = new ClientContext(spurl))
    context.Credentials =  new NetworkCredential("username", "password", "domain");


        Web web = context.Web;

    catch (Exception e)
        Console.WriteLine("Exception: "+e.Message);




Your Answer

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

Browse other questions tagged or ask your own question.