asp.net list of users by profile property
I have created some profile properties for when a new user is added to our system.
One property is called 'Client' and links this user to a part开发者_运维问答icular client and stores a client id.
I am trying to create a page that shows a list of users for each client on the system such as:
Client 1
User 1
User 2
User 3
Client 2
User 4
User 5
User 6
Client 3
User 7
User 8
User 9
Is there a way to get a list of users that match a particular profile property?
Thanks for any help. J.
The code below is an old VB.Net method I wrote to filter users based on a profile value. It could be slightly modified to accomplish your task.
Function FindUsers(ByVal prop As String, ByVal val As String) As List(Of ProfileCommon)
' Use a generic list of people
Dim peeps As New List(Of ProfileCommon)()
ViewState("prop") = prop
ViewState("val") = val
' Get all profile objects
Dim profiles As ProfileInfoCollection = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All)
' Go through the profiles
For Each info As ProfileInfo In profiles
' We need to turn a ProfileInfo into a ProfileCommon
' to access the properties to do the search
Dim userProfile As ProfileCommon = ProfileCommon.Create(info.UserName)
If Roles.IsUserInRole(info.UserName, "Members Subscribers") Then
' If the birthday matches
If val <> "" Then
If prop <> "" AndAlso Left(userProfile.Item(prop), val.Length) = val Then
' Add them to our list
peeps.Add(userProfile)
End If
Else
peeps.Add(userProfile)
End If
End If
Next
If peeps.Count > 0 Then ShowUserDetails(peeps(0).UserName)
Return peeps
End Function
Found what i was looking for, ended up using this: http://pretzelsteelersfan.blogspot.com/2007/03/get-aspnet-profile-properties-from-sql.html
Thanks for any help though.
精彩评论