Solved

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

Posted on 2014-04-16
6
643 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
  • 3
  • 3
6 Comments
 
LVL 26

Expert Comment

by:Alan Warren
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:pctechnicians
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
Thanks Alan, It worked.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

By this time the large percentage of day-to-day transactions have shifted to mobile banking; here are some overriding areas QAs must investigate while testing mobile banking apps.  
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now