Question

This code is supposed to be the simplest code for connecting. Like a "Hello World" program:

static void Main(string[] args)
{
    var targetSite = new Uri("http://w2k12spps02/sitios/ColeccionProyectos/default.aspx");
    var login = @"----@-----.net";
    var password = "----";

    var securePassword = new SecureString();
    foreach (char c in password)
    {
        securePassword.AppendChar(c);
    }

    var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);

    using (ClientContext clientContext = new ClientContext(targetSite))
    {
        clientContext.Credentials = onlineCredentials;
        Web web = clientContext.Web;
        clientContext.Load(web, webSite => webSite.Title);

        clientContext.ExecuteQuery();
        Console.WriteLine(web.Title);
    }
}

However, I'm getting this error in the ExecuteQuery() line:

An unhandled exception of type 'Microsoft.SharePoint.Client.ClientRequestException' occurred in Microsoft.SharePoint.Client.Runtime.dll

Additional information: The IDCRL response header from server 'http://w2k12spps02/' is not valid. The response header value is 'NTLM'. The response status code is 'Unauthorized'. All response headers are 'SPRequestGuid=dc82cc9d-24ea-c086-5d64-eb854b84146b, request-id=dc82cc9d-24ea-c086-5d64-eb854b84146b, X-FRAME-OPTIONS=SAMEORIGIN, MicrosoftSharePointTeamServices=15.0.0.4420, X-Content-Type-Options=nosniff, X-MS-InvokeApp=1; RequireReadOnly, Content-Length=16, Content-Type=text/plain; charset=utf-8, Date=Thu, 19 Jan 2017 09:13:53 GMT, Server=Microsoft-IIS/8.0, WWW-Authenticate=NTLM, X-Powered-By=ASP.NET'.

What's the problem? I don't know if the URL is wrong, whether the login information is wrong... or the whole piece of code is wrong!

Was it helpful?

Solution

You are using SharePointOnlineCredentials which is meant to be used when connecting to Office 365 tenants. You should connect to SharePoint 2013 on-premise by other means, depending on the authentication methods available on your server.

Your error message shows that NTLM is likelly to be the authentication mecanism expected by the server, so you should instead assign ClientContext.Credentials with an instance of NetworkCredential, see NetworkCredential on MSDN, but created from a windows user account, not from your "----@-----.net" account.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top