Solved

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

Posted on 2014-04-16
6
679 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
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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 500 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

One of the biggest threats in the cyber realm pertains to advanced persistent threats (APTs). This paper is a compare and contrast of Russian and Chinese APT's.
Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

789 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