To give a little background on my setup, I'm running SharePoint 2013 Foundation configured with SAML authentication using ADFS. I'm able to access the SharePoint site using a web browser from both the SharePoint server and other client workstations.

I have a VB.NET console app which has a reference to the Microsoft.SharePoint.Client dll. To keep it short, the console app is simply trying to retrieve the name of the SharePoint site by using the ClientContext and loading the Web class. The code is failing on context.ExecuteQuery() with a 403 Forbidden error. What am I missing here? My code is below. Thanks in advance!

Dim context As ClientContext = New ClientContext("https://sharepoint.mydomain.com")
context.Credentials = New NetworkCredential("<UserName>", "<Password>", "<Domain>")

Dim web As Web = context.Web
  • Facing the same issue. Any luck?
    – NLV
    May 22, 2015 at 18:27

1 Answer 1


Since the use of NetworkCredentials does not work with adfs I found another solution here.

It basicly forces SharePoint to go the Windows authentication way. Some infos here.

Anyway just add credentials and force SharePoint do what you want.

ctx.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
ctx.ExecutingWebRequest += new EventHandler<WebRequestEventArgs>ctx_MixedAuthRequest);

        void ctx_MixedAuthRequest(object sender, WebRequestEventArgs e)
                //add the header that tells SharePoint to use Windows Auth
                e.WebRequestExecutor.RequestHeaders.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
            catch (Exception ex)
                MessageBox.Show("Error setting auth header: " + ex.Message);

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.