I have a login page that verifies credentials with active directory and redirects to the next page. When I run it locally it works perfect, but when I put it out on our webserver it gives an error trying to create the group principal: (System.DirectoryServices.DirectoryServicesCOMException (0x80072020))
I need to find out why it would work on one and not the other. Any input is greatly appreciated.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain.com");
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Building Webmasters");
UserPrincipal up = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, txtUserName.Value);
bool auth = ctx.ValidateCredentials(txtUserName.Value, txtPassword.Value);
bool groupauth = grp.Members.Contains(up);
I figured out it was throwing the error on creating the user principal. So I changed it to grab the group principal and do a contains with an overload where I can just pass in the username from the form. This worked for me.
bool auth = ctx.ValidateCredentials(txtUserName.Value, txtPassword.Value);
bool groupauth = grp.Members.Contains(ctx, IdentityType.SamAccountName, txtUserName.Value);
bool adminauth = admingrp.Members.Contains(ctx, IdentityType.SamAccountName, txtUserName.Value);
User contributions licensed under CC BY-SA 3.0