?
Solved

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

Posted on 2014-04-16
6
Medium Priority
?
742 Views
Last Modified: 2014-04-24
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!
0
Comment
Question by:pctechnicians
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 26

Expert Comment

by:Alan Warren
ID: 40006090
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
0
 

Author Comment

by:pctechnicians
ID: 40006433
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
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 40008056
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
0
Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

 

Author Comment

by:pctechnicians
ID: 40018591
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
0
 
LVL 26

Accepted Solution

by:
Alan Warren earned 1500 total points
ID: 40018756
Hi Triveni,
it shouldn't be difficult to create a SqlDataSource that consumes your modified view "vw_aspnet_MembershipUsers"
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:YourConnectConnectionString %>" SelectCommand="Select * from vw_aspnet_MembershipUsers" SelectCommandType="Text" />

Open in new window

then bind your formview/gridview/detailsview to the SqlDataSource using the data control property DataSourceID
DataSourceID="SqlDataSource1"

Open in new window

Codeless Databinding!

Respectfully yours,
Alan
0
 

Author Comment

by:pctechnicians
ID: 40019914
Thanks Alan, It worked.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question