Solved

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

Posted on 2014-04-16
6
660 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
Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

 

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

Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Display mvc partial view with errors on parent page 1 26
yahoo Hacks 9 93
SSRS ReportViewer report timeout 7 103
Sonicwall blocks a site 49 56
Encryption for Business Encryption (https://en.wikipedia.org/wiki/Encryption) ensures the safety of our data when sending emails. In most cases, to read an encrypted email you must enter a secret key that will enable you to decrypt the email. T…
How important is it to take extra precautions to protect your online business? These are some steps you can take to make sure you're free of any cyber crime.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

910 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

22 Experts available now in Live!

Get 1:1 Help Now