1

Have been tasked to connect with a SharePoint site hosted by another company...when asked about theitr authorisation this is the response I got..

The authentication is annoying to work with in code. I think you need to set up a credential cache in code, as well as setting some headers in the request. You might also have to manage the initial 401, and subsequent redirect to authenticate as NTLM is a multi-step authentication

I'm assuming they are referring to the Infamous Double Hop Sharepoint issue...I'm using the below code to connect but am being Refused (Error 401 Unauthorised).

I really have no further ideas...anyone?

            try
        {
            this.Cursor = Cursors.WaitCursor;

            Uri uri = new Uri(FbaTxt.Text);

            ClientContext ctx = new ClientContext(uri);

            NetworkCredential nc = new NetworkCredential(USER, PWD, DOMAIN);
            CredentialCache cc = new CredentialCache();
            cc.Add(uri, "NTLM", nc);
            ctx.Credentials = cc;

            //get the web
            Web w = ctx.Web;

            //LOAD LISTS WITH ALL PROPERTIES
            var lists = ctx.LoadQuery(w.Lists);

            //execute the query
            ctx.ExecuteQuery();

            FbaLst.Items.Clear();
            foreach (List theList in lists)
            {
                FbaLst.Items.Add(theList);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error: " + ex.Message);
        }
        finally
        {
            this.Cursor = Cursors.Default;
        } 
0

I doubt this is a double-hop issue since you're passing explicit credentials.
However, I don't understand this piece of code:

        NetworkCredential nc = new NetworkCredential(USER, PWD, DOMAIN);
        CredentialCache cc = new CredentialCache();
        cc.Add(uri, "NTLM", nc);
        ctx.Credentials = cc;

Should simply be IMO:

        NetworkCredential nc = new NetworkCredential(USER, PWD, DOMAIN);
        m_ctx.AuthenticationMode = ClientAuthenticationMode.Default;
        ctx.Credentials = nc;
1
  • The above change to the code worked...thx...!! – Tim Cadieux Jan 27 '16 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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