A question that is asked regularly is how to do forms authentication when you’re using the SharePoint client object model. We have blogged about this before at
http://sharepointdragons.com/2012/04/20/authentication-when-using-the-sharepoint-client-object-model/
, but the solution below is clean and well worth to mention (it uses the managed client object model):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Microsoft.SharePoint.Client;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
try
{
using (var context = new ClientContext(“http://astro:46454″))
{
context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
FormsAuthenticationLoginInfo formsAuthInfo = new FormsAuthenticationLoginInfo(“anton”, “anton!0″);
context.FormsAuthenticationLoginInfo = formsAuthInfo;
var site = context.Site;
context.Load(site);
context.ExecuteQuery();
Console.WriteLine(site.Url);
}
}
catch (Exception err)
{
var errMsg = err.Message;
}
}
}
}
Like this:
Like Loading...
Hi guys – hope you don’t mind but I made your blog the featured blog in this week’s Newsletter : http://www.collaboris.com/sharepoint-newsletters/sharepoint-newsletter-50. Thanks Mark.