asp.net список пользователей по профилю - PullRequest
1 голос
/ 10 октября 2011

Я создал несколько свойств профиля для добавления нового пользователя в нашу систему.

Одно свойство называется «Клиент» и связывает этого пользователя с конкретным клиентом и сохраняет идентификатор клиента.

Я пытаюсь создать страницу, которая показывает список пользователей для каждого клиента в системе, например:

Client 1
   User 1
   User 2
   User 3
Client 2
   User 4
   User 5
   User 6
Client 3
   User 7
   User 8
   User 9

Есть ли способ получить список пользователей, которые соответствуют определенному свойству профиля?

Спасибо за любую помощь.J.

Ответы [ 2 ]

1 голос
/ 11 октября 2011

Нашел то, что искал, в итоге использовал это: http://pretzelsteelersfan.blogspot.com/2007/03/get-aspnet-profile-properties-from-sql.html

Спасибо за любую помощь.

1 голос
/ 11 октября 2011

Код ниже - это старый метод VB.Net, который я написал для фильтрации пользователей по значению профиля.Это может быть немного изменено для выполнения вашей задачи.

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