SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to connect to SP2010 server with claims based authorization via client context. But I have security issue. First I didn't managed to connect with default credentials. Then I wrote:

NetworkCredential credentials = new NetworkCredential("myusername", "mypass"); clientContext.Credentials = credentials;

After that i got error status: "Forbidden". I googled and found this solution:

static void clientContext_ExecutingWebRequest(object sender, WebRequestEventArgs e){ e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");

clientContext.ExecutingWebRequest += new EventHandler(clientContext_ExecutingWebRequest);

I did that also, but then got error: "Unauthorized", despite the fact that i have user with above credentials and I can normally logon with his username and password.

Any suggestion?

Update: If I remove "NetworkCredential credentials = new NetworkCredential("myusername", "mypass"); clientContext.Credentials = credentials;" and leave above eventhandler, I become able to execute client context. I assume that he now use windows authentication and that is ok, in some way. But what I must do to enable forms-based (membership provider) auth via client context? Is that even possible?

share|improve this question
Is this a local machine or domain user identity? – SPDoctor Jan 24 '11 at 12:27
I use membership provider, and that user is in my aspnet_Users table (aspnetdb database) - he isn't domain user. – trip Jan 24 '11 at 12:38
I have this same problem. Trip could you tell me how you resolve your issue not using FormsAuthenticationLoginInfo? – user21763 Jan 6 '14 at 21:40
up vote 2 down vote accepted

Windows authentication is the default authentication mode. You can also choose Anonymous or Forms authentication by setting the authentication mode.

Try something like this:

  ClientContext ctx = new ClientContext("http://myserver/");
  FormsAuthenticationLoginInfo login = new FormsAuthenticationLoginInfo("bill", "password");
  ctx.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
  ctx.FormsAuthenticationLoginInfo = login;

The snippet you give in your question is actually disabling forms authentication, so I suggest not using it.

share|improve this answer
Thanx. it works. I tried in similar way, but not using FormsAuthenticationLoginInfo, which was mistake :( – trip Jan 24 '11 at 15:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.