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 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;
            }
        }
    }
}

About these ads

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 : http://www.collaboris.com/sharepoint-newsletters/sharepoint-newsletter-50. Thanks Mark.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 377 other followers

%d bloggers like this: