Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 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 at 21:40

1 Answer 1

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

 
discard

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.