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?

3
  • Is this a local machine or domain user identity? Commented Jan 24, 2011 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. Commented Jan 24, 2011 at 12:38
  • I have this same problem. Trip could you tell me how you resolve your issue not using FormsAuthenticationLoginInfo? Commented Jan 6, 2014 at 21:40

1 Answer 1

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.

1
  • Thanx. it works. I tried in similar way, but not using FormsAuthenticationLoginInfo, which was mistake :( Commented Jan 24, 2011 at 15:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.