using (var context = new ClientContext("https://848-sharepoint:16543"))
                var ss = new System.Security.SecureString();
                Array.ForEach("xxxxxxx".ToCharArray(), (c) => { ss.AppendChar(c); });
                context.Credentials = new SharePointOnlineCredentials("[email protected]", ss);
                var web = context.Web;
                var title = web.Title;

detail error:-An unhandled exception of type 'System.Net.WebException' occurred in Microsoft.SharePoint.Client.dll

Additional information: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

Do i need ADFS set up for this to work this or sharepointonlinecrdentials will handle this? I require single sign on but i also not able to get authcookie from this? it gets null.

        Uri newUri = new Uri("https://848-sharepoint:16543");
        var ss = new System.Security.SecureString();
        Array.ForEach("xxxxx".ToCharArray(), (c) => { ss.AppendChar(c); });
        SharePointOnlineCredentials a = new        SharePointOnlineCredentials("[email protected]", ss);
        var s = a.GetAuthenticationCookie(newUri); 

edit:- I am not using sharepointonline rather it is sharepoint 2013.can u provide some sample code?

  • I have one site with ADFS enabled and another sharepoint site with normal. I can access both site through IE but i can see that there is certificate address mismatch.it is self sign certificate. what should i have to do ?
    – Dew
    Aug 14, 2015 at 14:32

1 Answer 1


Whenever I have seen that error it has been a certificate trust issue. If you browse to the site using IE on the same machine using the same user account that code runs on, can you browse the site successfully or do you get a certificate error?

I have used the SharePointOnlineCredentials object with both ADFS and Cloud / Office 365 only accounts and it works for both scenarios. Though with a cloud account scenario, typically the user name would be something like [email protected] (though I suppose this depends on your domain set up).

  • yes,it is certificate trust issue.It is resolved by ignoring certificate error code and demo application run successfully.Thanks.
    – dew
    Aug 31, 2015 at 16:20

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.