views:

833

answers:

2

I have a WSS 3.0 site (no MOSS) that uses a custom forms authentication membership provider and role manager, authenticating users against a remote web service (although at the moment it works against moq data). My problem is this: users when logged in have their name shown as being their login name, not their full name.

I set up my provider so that both the username and fullname are stored, and that when asked (e.g. GetUserByUsername) either value will return a MembershipUser object with the Fullname as the username. This has the effect that in the sharepoint people picker, entering a users username results in the auto complete turning it into their fullname, much like the standard windows auth does.

However, breakpointing the provider, when logging in to the site only the ValidateUser method on the provider is called, their is never a request for my doctored MembershipUser objects. Looking at the UserInfo table in the content database a new entry is created with the user name (tp_title) set to their login name.

Short of running a direct query against the database (which I am not going to do) I am unsure how I can have a user friendly username for custom FBA users. Help would be appreciated.

+1  A: 

Nevermind, found a way around it. On the validate user method of my custom membership provider, the following code allows me to set the name property. This might not scale when using thousands of users, but for small user bases it should be fine:

public override bool ValidateUser(string username, string password)
    {
        if (moqUsers.Any(user => user.Username.Equals(username) && user.Password.Equals(password)))
        {
            SPContext.Current.Site.RootWeb.AllowUnsafeUpdates = true;
            var user = SPContext.Current.Site.RootWeb.EnsureUser(username);
            user.Name = RetrieveUserFullName(username);
            user.Update();
            SPContext.Current.Site.RootWeb.AllowUnsafeUpdates = false;
            return true;
        }
        return false;
    }

Also, there might need to be a good disposal of rootweb in the above.

Aquinas
I do the Same Step while adding the User to SharePoint.
Kusek
A: 

I tried a lot to get the code above to work during ValidateUser, which I think is a great time to update UserInfo.tp_Title (except maybe for the fact that you're going to update it every time the user logs in, but hey, what are you going to do?).

However, I was unable to get EnsureUser to function (also tried AllUsers[]) without throwing errors. Tried executing within an anonymous delegate under SPSecurity.RunWithElevatedPrivileges and all. No dice.

Thing is, though, that I think this is totally the right idea, and I just want to share that the way I got it working is through a call to the SP UserGroup web service (/_vti_bin/usergroup.asmx), calling UpdateUserInfo. The exact method signature for me looks something like:

UserGroup.UpdateUserInfo("custommembershipprovidername:" + username, TheFullName,
 emailAddress, string.Empty)
Todd Sprang