1

I create a farm solution that query in a list of SharePoint 2013.

When I run my solution in a development server using Context.Credentials = new NetworkCredential('user', 'pass', 'domain'), the query worked normally.

I add and active my solution in my production SharePoint Server, when I run the query into SharePoint Server, return erro 401.. My class of query:

public class Campanhas
{   
    public ListItemCollection GetItemsListCampanha(string CAML)
    {            
        using (ClientContext contextCallCenter = new ClientContext("http://SharePointSite/subsite/subsite/"))
        {
            contextCallCenter.Credentials = new NetworkCredential("login", "password", "domain");
            List ListCampanha = contextCallCenter.Web.Lists.GetByTitle("List Name");
            contextCallCenter.ExecuteQuery();
            CamlQuery queryCallCenter = new CamlQuery();
            queryCallCenter.ViewXml = CAML;
            ListItemCollection ListItemCampanha = ListCampanha.GetItems(queryCallCenter);

            contextCallCenter.Load(ListItemCampanha);
            contextCallCenter.ExecuteQuery();

            return ListItemCampanha;
        }
    }
}

Update: In Consolle Aplication not return error.

6
  • Why are you using the client object model in a farm solution? Oct 16 '13 at 18:15
  • Because her access other sites on my sharepoint Oct 16 '13 at 18:23
  • Maybee clarify that in the question :) Oct 16 '13 at 18:45
  • By the way, other sites is no reason for using client object model. Different farms is though. Oct 16 '13 at 18:46
  • Really, in the dev Machine is in other farm, but the solution add in current farm... Oct 16 '13 at 18:48
1

This is caused by NTLM Double Hop authentication. This is why you are getting it on the server and not on a another machine.

Use the server sdk. If you need to execute it as a specific user then try this:

        SPUser user = SPContext.Current.Web.EnsureUser("login");

        //this creates the site and web objects as the user.
        using(SPSite site = new SPSite(SITE_URL, user.UserToken))
        {
            using(SPWeb web = site.OpenWeb(WEB_URL))
            {
                // get your list items here.
            }
        }
3
  • And...In a ConsoleApplication all ok, in solution not work... Oct 16 '13 at 19:56
  • Does the person you're trying to impersonate have at least Visitor(read) permissions on the web and list?
    – Chad Beard
    Oct 17 '13 at 13:17
  • Not, this user have Full Controll Oct 17 '13 at 17:31
0

This might be a classical LoopbackCheck 401, where the server blocks calls made to itself resolved with a host header other than FQDN or NetBIOS name unless the domain name is registered in BackConnectionHostnames key. See also Spencer Harbar's article DisableLoopbackCheck & how it affects SharePoint and http://support.microsoft.com/kb/896861.

Take a look at this script by Jeremy Jameson that will help you implement the change:

https://github.com/jeremy-jameson/Toolbox/blob/master/PowerShell/Add-BackConnectionHostNames.ps1

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.