i have code to create user directly in active directory for ADFS my sample code -
PrincipalContext principalContext = null;
try
{
principalContext = new PrincipalContext(ContextType.Domain);
UserPrincipal usr = UserPrincipal.FindByIdentity(principalContext, txt_username.Text);
if (usr != null)
{
MessageBox.Show(txt_username.Text + " already exists. Please use a different User Logon Name.");
}
else
{
UserPrincipal userPrincipal = new UserPrincipal(principalContext);
userPrincipal.Surname = txt_lastname.Text;
userPrincipal.GivenName = txt_firstname.Text;
userPrincipal.EmailAddress = txt_email.Text;
userPrincipal.UserPrincipalName = txt_username.Text + "@ad.net";
userPrincipal.SamAccountName = txt_username.Text;
userPrincipal.DisplayName = txt_lastname.Text + " " + txt_firstname.Text;
userPrincipal.SetPassword(txt_pwd.Text);
userPrincipal.Enabled = true;
userPrincipal.PasswordNeverExpires = true;
userPrincipal.Save();
MessageBox.Show("user Created Sucessfully");
}
}
catch (Exception ex)
{
MessageBox.Show("Failed to create PrincipalContext. Exception: " + ex);
}
its work fine with window application ,but if i am putting same application in asp.net its throw error -
userPrincipal Exception:Access is denied
any suggestion
Thanks