I have a site at SharePoint on-Premises which has both Form based authentication and windows authentication enabled. Users can login using either of them. Now, I try to use Client Object Model for an application. Here is the code:
ClientContext context = new ClientContext("http://mySPSite/sites/doc");
//context.Credentials = CredentialCache.DefaultNetworkCredentials;
context.Credentials = new System.Net.NetworkCredential("myUserName", "myPassword", "myDomain");
Web site = context.Web;
context.Load(site);
context.ExecuteQuery();
Console.WriteLine("Title: {0}", site.Title);
However, no matter use default network credential or a valid credential, it shows this error:
{X-SharePointHealthScore: 0
SPRequestGuid: 45daf89c-2c2c-2007-4cbd-671a480d321e
request-id: 45daf89c-2c2c-2007-4cbd-671a480d321e
X-FRAME-OPTIONS: SAMEORIGIN
SPRequestDuration: 82
SPIisLatency: 0
X-Forms_Based_Auth_Required: http://******/_login/default.aspx?ReturnUrl=/_layouts/15/error.aspx&Source=%2fsites%2fdoc%2f_vti_bin%2fsites.asmx
X-Forms_Based_Auth_Return_Url: http://*****/_layouts/15/error.aspx
X-MSDAVEXT_Error: 917656; Access denied. Before opening files in this location, you must first browse to the web site and select the option to login automatically.
MicrosoftSharePointTeamServices: 15.0.0.4420
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
Content-Length: 13
Cache-Control: private, max-age=0
Content-Type: text/plain; charset=utf-8
Date: Thu, 02 Apr 2015 18:49:30 GMT
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
}
Obviously, this is the issue:
X-MSDAVEXT_Error: 917656; Access denied. Before opening files in this location, you must first browse to the web site and select the option to login automatically.
Anyone knows how to fix this? Or, Maybe better NOT use SCOM? Use server Model?
Thanks
Add more info:
If go to http://mySPSite/sites/doc by browser, it shows below form. In the code, I want to use Windows or Form based authentication, as long as one works.