2011-10-10 35 views
1

我創建了一些配置文件屬性,用於將新用戶添加到我們的系統。asp.net用戶按配置文件屬性列表

一個屬性稱爲「客戶端」,並將該用戶鏈接到特定客戶端並存儲客戶端ID。

我想創建一個網頁,顯示了每個客戶端的系統,例如在用戶的列表:

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.

回答

1

下面的代碼是我寫的基於配置文件值過濾用戶的舊的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 
+0

感謝zackg,那裏沒有內置的解決方案。我會玩這個,讓你知道我如何繼續....再次感謝。 – JBoom

相關問題