0

ユーザーを承認するときに考慮すべきさまざまな種類の役割があります。例: John は、新しいコンピュータを注文するには、ポジションマネージャを持ち、事務用品部門の一員である必要があります。

Roles の問題は、Roles.GetRolesForUser("John") が文字列配列しか返せないことです。

カスタム roleProvider とカスタム roleManager を使用する必要がありますか? または、GetUsersWithProfileProperties() などのメソッドを追加するカスタム ProfileManager を開発する必要がありますか?

どんな提案でも大歓迎です!

ティボー

編集: 上記の例は単純化されており、4 つの異なるコレクションである 4 種類のロールを持つことができます。

編集:非常によく似た質問を見つけました

4

4 に答える 4

2

あなたが書いたものから; 必要なものはすべて、すぐに利用できると思います。

    // Return all Users in a  Role
    string[] users;
    users = Roles.GetUsersInRole("RoleName");
    // Return all Roles for a User
    string[] roles;
    roles = Roles.GetRolesForUser();
    // Search through Membership store locating users with a role
    MembershipUserCollection mu;
    mu = Membership.GetAllUsers();
    // Loop through all membership users looking for users in a role

    foreach(MembershipUser m in mu){
        if(Roles.IsUserInRole(m.UserName, "Role Name")){
            // Do something

            // We can even nest to x levels
            if (Roles.IsUserInRole(m.UserName, "Another Role")){

                // Do something else
            }
        }
    }

私があなたの質問を誤解したかどうかを明確にしてください。

于 2009-11-24T11:53:24.963 に答える
1

各従属ロール プロバイダーにアクセスするための Path-To-Level typew 規則を使用して "CompositeRoleProvider" を作成してみませんか。複数のロール プロバイダーを作成する必要がありますが、複合プロバイダーまたは最上位プロバイダーがすべての作業を行います。ProfileProvider で同様のことを行う予定です

于 2009-11-27T20:04:02.223 に答える
-1

メソッド GetUsersInRole があると思います。 http://msdn.microsoft.com/en-us/library/system.web.security.roles.getusersinrole.aspx

于 2009-11-24T11:32:55.017 に答える