views:

121

answers:

1

I have the ASP.NET application. I use authentication with user profiles. I use SQL Server as a data provider. What I want to do is to get fill the GridView control with all the users in the system with additional profile information.

For now I do like this:

UserAccounts.DataSource = Membership.GetAllUsers();
UserAccounts.DataBind();

With that I can make a list with fields: UserName and Email. But now I want to add First and LastName fields which I store as a Profile informations.

I have found this post and tried to do like this:

ProfileInfoCollection profiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);
DateTime lastActivity = profiles["some_username"].Email;

but this gives me only standard user fields, like Email, LastActivityDate, etc. Later I've tried to call the function for ever row in GridView table.

public string GetProfileValue(string name, string UserName)
{
    ProfileBase pb = ProfileBase.Create(UserName, true);
    return pb.GetPropertyValue(name).ToString();
}

But I don't think it is efficient to query database for every field with profile information. I was thinking of joining aspnet_Users and aspnet_Profile tables, but the FirstName and LastName fields are stored like this:

UserId | PropertyNames                   | PropertyValuesString | ....
----------------------------------------------------------------------
someId | FirstName:S:0:6:LastName:S:6:5: | ThomasSmith          | ....

so that means that I have to parse the strings to get my values.

My questions are:

  1. Is it a good policy to query the aspnet_ tables directly using SELECT?
  2. How to get the GridView which contain UserName, Email, LastActivityDate, FirstName, LastName (the standard and profile information together).
A: 

As you've found, the default ASP.NET profile provider stores all the profile information in a single, colon separated field for each user.

You'd be better off looking at the SQL Table Profile Provider Sample released by MS. This will enable you to create a nicely query-able table based profile, that you can then pass into your GridView.

Zhaph - Ben Duguid