2

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?

  • Is this a local machine or domain user identity? – SPDoctor Jan 24 '11 at 12:27
  • I use asp.net 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
2

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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