R – FBA Display Name with custom membership provider, WSS 3.0

fbamossnetsharepointwss-3.0

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.

Best Answer

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.

Related Topic