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