I have a Windows 7 system built (per MS' instructions) with SharePoint 2010 Server. I'm writing a simple console application on it that attempts to use SharePoint's Managed Client Object Model to connect to the SharePoint instance running on the same system as the console application (this is a development rig).
using (ClientContext context = new ClientContext("http://localhost"))
{
context = new NetworkCredential("username", "password", "domain");
Web web = context.Web;
context.Load(web);
Log.Debug("Loading web.");
context.ExecuteQuery();
Console.WriteLine(web.Title);
}
Upon calling ExecuteQuery, the application throw a System.Net.WebException.
System.Net.WebException : The remote server returned an error: (401) Unauthorized.
Stack Trace:
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
The user account I'm creating the NetworkCredential
with is a site collection administrator (and, incidentally, is also a farm admin as this is just a development machine).
- Is there a way to configure the Managed Client Object Model's permissions?
- Why might a user with such credentials be Unauthorized to use to the Managed Client Object Model?
Update 1:
I'm seeing the 401 in the IIS log with:
sc-substatus = 2,
sc-win32-status = 5
Update 2:
Per Steve B's advise, I've done the following:
- Disabled Kerberos as an available authentication provider in my IIS 7 configuration (so it uses NTLM exclusively) by running the following command:
- %WINDIR%\system32\inetsrv\appcmd set config /section:windowsAuthentication /-providers.[value='Negotiate']
- The IIS web was already set to use Windows Authentication
- %WINDIR%\system32\inetsrv\appcmd set config /section:windowsAuthentication /-providers.[value='Negotiate']
- Restarted computer.
- Trying upon returning yielded new log results. Described below.
- Created the
DisableStrictNameChecking
REG_DWORD key atHKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanmanServer\Parameters
and set its value to a Decimal 1. - Whitelisted the loopback check by creating the
BackConnectionHostNames
Multi-String Value atHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
and added my system's short and full hostnames (one per line) to the value. - Restarted computer.
- This yielded the same log results mentioned previously (again, provided below) but changed the logged server address from a complete IPv6 address to an IPv6 loopback address (::1).
- Disabled the loopback check entirely by creating REG_DWORD
DisableLoopbackCheck
atHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
and setting value to Decimal 1.- Restarted and tried again: this yielded no change since #5 so I reverted to the whitelist solution.
The codes in the log have changed with these adjustments. I see the following every time I run my application:
- 401.2, sc-win32-status 5
- 401.1, sc-win32-status 2148074254
- 401.1, sc-win32-status 2148074252