SharePoint Dragons

Nikander & Margriet on SharePoint

Forms authentication using the Client Object Model

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 , 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)
                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;
            catch (Exception err)
                var errMsg = err.Message;

One response to “Forms authentication using the Client Object Model

  1. Mark Jones June 12, 2012 at 9:45 pm

    Hi guys – hope you don’t mind but I made your blog the featured blog in this week’s Newsletter : Thanks Mark.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: