Link to home
Start Free TrialLog in
Avatar of pctechnicians
pctechnicians

asked on

how to get the user's first and last name , organization information using membership.getusers()

I have an application. It shows the user information like, username(login name), email address, locked out or not, last view date etcs.,

But, I need to know the users first and last names and little more information.
My datagrid's datasource is pointed to membership.getusers()  method.

Not sure which view it accesses? I am guessing it accesses vw_aspnet_membershipusers.

I tried modifying this view but still the application doesn't show the first and last names/
Please help me.

Thanks!
Avatar of Alan Warren
Alan Warren
Flag of Philippines image

Hi

The aspnet membership provider doesn't store firstname and lastname properties for users, only username. The provider can be modified to store additional information, which can be collected at sign up, but that information gets stored in the table aspnet_Profile.

If your membership provider has been modified to use additional profile properties they will be available by referencing my.user.propertyname, e.g.
strFirstName=My.User.FirstName

Open in new window

To configure your membership provider to parse profile properties you need to define a profile provider in the root web.config file
    <profile enabled="true" defaultProvider="CustomizedProvider">
      <!-- Custom profile properties -->
      <providers>
        <remove name="CustomizedProvider" />
        <add name="CustomizedProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="cnAspNet" applicationName="aspnet"  />
      </providers>
      <properties>
        <add name="FirstName" type="String" allowAnonymous="false" />
      </properties>
    </profile>

Open in new window

Excellent tutorials by Scott Mitchel here:
Examining ASP.NET's Membership, Roles, and Profile - Part 1


Respectfully yours,
Alan
Avatar of pctechnicians
pctechnicians

ASKER

Alan,

Thanks for your reply. I tried adding the profile section to the web config file.

Still I am having the same problem. BTW, I don't see the table called aspnet_profile in the database.
All the information related to firstname, lastname, organizations, etc., goes in to a table called User_ExtraInfo.

I have modified the view ( vw_aspnet_MembershipUsers ) to get the firstname and last name by joining to the above mentioned table.

Below you can find the original view and modified view.

Original View:

 ALTER VIEW [dbo].[vw_aspnet_MembershipUsers]
  AS SELECT [dbo].[aspnet_Membership].[UserId],
            [dbo].[aspnet_Membership].[PasswordFormat],
            [dbo].[aspnet_Membership].[MobilePIN],
            [dbo].[aspnet_Membership].[Email],
            [dbo].[aspnet_Membership].[LoweredEmail],
            [dbo].[aspnet_Membership].[PasswordQuestion],
            [dbo].[aspnet_Membership].[PasswordAnswer],
            [dbo].[aspnet_Membership].[IsApproved],
            [dbo].[aspnet_Membership].[IsLockedOut],
            [dbo].[aspnet_Membership].[CreateDate],
            [dbo].[aspnet_Membership].[LastLoginDate],
            [dbo].[aspnet_Membership].[LastPasswordChangedDate],
            [dbo].[aspnet_Membership].[LastLockoutDate],
            [dbo].[aspnet_Membership].[FailedPasswordAttemptCount],
            [dbo].[aspnet_Membership].[FailedPasswordAttemptWindowStart],
            [dbo].[aspnet_Membership].[FailedPasswordAnswerAttemptCount],
            [dbo].[aspnet_Membership].[FailedPasswordAnswerAttemptWindowStart],
            [dbo].[aspnet_Membership].[Comment],
            [dbo].[aspnet_Users].[ApplicationId],
            [dbo].[aspnet_Users].[UserName],
            [dbo].[aspnet_Users].[MobileAlias],
            [dbo].[aspnet_Users].[IsAnonymous],
            [dbo].[aspnet_Users].[LastActivityDate]
  FROM [dbo].[aspnet_Membership] INNER JOIN [dbo].[aspnet_Users]
      ON [dbo].[aspnet_Membership].[UserId] = [dbo].[aspnet_Users].[UserId]

Modified View:

VIEW [dbo].[vw_aspnet_MembershipUsers]
  AS SELECT [dbo].[aspnet_Membership].[UserId],
            [dbo].[aspnet_Membership].[PasswordFormat],
            [dbo].[aspnet_Membership].[MobilePIN],
            [dbo].[aspnet_Membership].[Email],
            [dbo].[aspnet_Membership].[LoweredEmail],
            [dbo].[aspnet_Membership].[PasswordQuestion],
            [dbo].[aspnet_Membership].[PasswordAnswer],
            [dbo].[aspnet_Membership].[IsApproved],
            [dbo].[aspnet_Membership].[IsLockedOut],
            [dbo].[aspnet_Membership].[CreateDate],
            [dbo].[aspnet_Membership].[LastLoginDate],
            [dbo].[aspnet_Membership].[LastPasswordChangedDate],
            [dbo].[aspnet_Membership].[LastLockoutDate],
            [dbo].[aspnet_Membership].[FailedPasswordAttemptCount],
            [dbo].[aspnet_Membership].[FailedPasswordAttemptWindowStart],
            [dbo].[aspnet_Membership].[FailedPasswordAnswerAttemptCount],
            [dbo].[aspnet_Membership].[FailedPasswordAnswerAttemptWindowStart],
            [dbo].[aspnet_Membership].[Comment],
            [dbo].[aspnet_Users].[ApplicationId],
            [dbo].[aspnet_Users].[UserName],
            [dbo].[aspnet_Users].[MobileAlias],
            [dbo].[aspnet_Users].[IsAnonymous],
            [dbo].[aspnet_Users].[LastActivityDate],
                                   [dbo].[User_ExtraInfo].[FirstName],
  [dbo].[User_ExtraInfo].[LastName],
  [dbo].[User_ExtraInfo].[Degree],
  [dbo].[User_ExtraInfo].[Organization]              
  FROM [dbo].[aspnet_Membership] INNER JOIN [dbo].[aspnet_Users]
      ON [dbo].[aspnet_Membership].[UserId] = [dbo].[aspnet_Users].[UserId]
LEFT JOIN [dbo].[user_extrainfo]       ON   [dbo].[aspnet_Membership].[UserId] =[dbo].[user_extrainfo].[userid]

I am pretty sure that Membership.GetUsers() uses this view because no other view is returning all the data required by the datagrid.

Thanks for your help again.

Triveni
Hi Triveni,

I use a gridview like:
    <asp:GridView ID="UserAccounts" runat="server" AutoGenerateColumns="False" Width="530px" Font-Size="Smaller" >  
      <Columns>  
        <asp:HyperLinkField Text="{0}" DataNavigateUrlFields="UserName" 
            DataNavigateUrlFormatString="~/profiles/viewprofile.aspx?n={0}" 
            DataTextField="UserName" HeaderText="Members" SortExpression="IsOnline" />
        <asp:BoundField DataField="LastLoginDate" HeaderText="Last Login" dataformatstring="{0:f}" />
        <asp:CheckBoxField DataField="IsOnline" HeaderText="Online"  /> 
         
      </Columns> 
    </asp:GridView>

Open in new window

And populate it like this:
        UserAccounts.DataSource = Membership.GetAllUsers()
        UserAccounts.DataBind()

Open in new window

I don't have the view vw_aspnet_MembershipUsers installed, so I'm fairly sure  the Membership.GetAllUsers() method does not consume the view vw_aspnet_MembershipUsers, I think it probably consumes the StoredProcedure [dbo].[aspnet_Membership_GetAllUsers]

Respectfully yours,
Alan
Alan,

I have modified that stored procedure as well. But, here the thing is the class is not declared with the other variables like (name,organization etc.,)

Looks like Instead of usging Membership.GetAllUsers() I will have to call the stored procedure directly. I will let you know once I am successful doing that.

Thanks for your help.
Triveni
ASKER CERTIFIED SOLUTION
Avatar of Alan Warren
Alan Warren
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Alan, It worked.