Error with UserPrincipal.GetAuthorizationGroups() method

前端 未结 3 1387
半阙折子戏
半阙折子戏 2021-02-08 21:42

I am having an issue using the GetAuthorizationGroups method of the UserPrincipal class in a web application.

Using the following code, I am receiving \"While trying to

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-08 22:17

    Error 5 indicates ERROR_ACCESS_DENIED, which suggests a permissions related issue. That said, the following code has just worked for me, running on Windows 7 with the website running as the default application pool:

    Content of "body" of .aspx page:

    
    
    

    Code-behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        var Context = new PrincipalContext(ContextType.Domain, "logon_domain", "username", "password");
        var principal = UserPrincipal.FindByIdentity(Context, "user_to_query");
        var groups = principal.GetAuthorizationGroups();
    
        GridView1.DataSource = groups;
        GridView1.DataBind();
    }
    

    In my example logon_domain was the lefthand of domain_name\username, rather than the style of domain specification you'd used. My solution may or may not work for you. If it doesn't, it does point to a permissions issue somewhere.

提交回复
热议问题