开发者

MVC 3 Not Recognizing Windows Role (Group)?

Has anybody come across occurrences where MVC does not recognize roles fr开发者_JS百科om Windows? I thought that roles translated to groups in Windows, but for some reason when I add a user to a group, check in MVC (using windows authentication) if that user.IsInRole("GroupJustAddedTo") always returns false. I have no idea why....Working in Server 2003 R2 with Windows Authentication enabled around the board. Confused :~( ???


Without knowing anything else, it makes me wonder if perhaps your MVC is not really connected to your AD server. Also, perhaps the user that is fetching the groups doesn't have sufficient privileges? Just some initial thoughts.

EDIT

We ended up writing our own RoleProvider. Here is the overloaded GetRolesForUser code

public override string[] GetRolesForUser(string userName)
{
    List<string> allRoles = new List<string>();
    PrincipalContext context;
    context = new PrincipalContext(ContextType.Domain, "hlpusd.k12.ca.us", "DC=hlpusd,DC=k12,DC=ca,DC=us");
    UserPrincipal user = UserPrincipal.FindByIdentity(context, userName);
    PrincipalSearchResult<Principal> usergroups = user.GetGroups(); // list of AD groups the user is member of
    IEnumerator<Principal> eGroup = usergroups.GetEnumerator();
    while (eGroup.MoveNext())
    {
        allRoles.Add(eGroup.Current.Name);
    }

    return allRoles.ToArray();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜