Question

We are successfully adding a new user to our Forms Based Authentication Provider using the Membership class in C#. We are able to login some public sites but after trying to search for the new created user in the people picker he doesn't show up.

Seems like we have to add a UserInfo record in the WSS_Content_* Database. So we referenced the people.asmx Web Service running on our Sharepoint. After trying to create the UserInfo using the following method, the method returns a not resolved PrincipalInfo object (UserInfoID is -1, IsResolved is false, etc.).

peopleservice.People service = new peopleservice.People();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
string[] users = new string[] { txtCreateEmail.Text };
var result2 = service.ResolvePrincipals(users, brnextranet.SPPrincipalType.User, true);

Are there any steps we are missing?

Was it helpful?

Solution

I was able to solve the issue by creating a Web Service running on the Sharepoint Server. The following two methods are required to create a UserInfo record:

    [WebMethod]
    public void CreateUser(string username)
    {
        SPWeb web = new SPSite(this.ExtranetSite).OpenWeb();

        web.AllUsers.Add(this.MembershipProvider + ":" + username, username, username, "");
        web.EnsureUser(this.MembershipProvider + ":" + username);
    }

    [WebMethod]
    public void DeleteUser(string username)
    {
        SPWeb web = new SPSite(this.ExtranetSite).OpenWeb();

        web.SiteUsers.Remove(this.MembershipProvider + ":" + username);
        web.Update();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top