0
Good!
I took part of a code that creates a user in AD with C#, the problem is when I call the method, I am beginner in programming, I will pass the code and the error.
private static DirectoryResponse EnviarRequisicaoLdap(DirectoryRequest request)
{
LdapConnection ldapConexao = new LdapConnection(new LdapDirectoryIdentifier(LdapServidor, LdapPorta));
try
{
// Tipo de autenticação com o LDAP
ldapConexao.AuthType = AuthType.Basic;
// Envia as credenciais com o dn completo
NetworkCredential credenciais = new NetworkCredential(LdapUsuario, LdapSenha);
// Estabele a conexão com o LDAP
ldapConexao.Bind(credenciais);
// Envia a requisição ao LDAP
return ldapConexao.SendRequest(request);
}
finally
{
// Libera a conexão com o LDAP.
if (ldapConexao != null)
ldapConexao.Dispose();
}
}
public static bool IncluirUsuario(Usuario usuario)
{
if (usuario != null)
{
string dn = string.Format("uid={0},{1}", usuario.Email, LdapUnidadeOrganizacional);
AddRequest addRequest = new AddRequest(dn);
addRequest.Attributes.AddRange(new DirectoryAttributeCollection() {
new DirectoryAttribute("objectClass", LdapObjectClass),
new DirectoryAttribute("uid", usuario.Email),
new DirectoryAttribute("cn", usuario.Nome),
new DirectoryAttribute("sn", usuario.Sobrenome),
new DirectoryAttribute("userPassword", ConverterSenhaLdapMD5(usuario.Senha)),
});
// Acessando o LDAP
EnviarRequisicaoLdap(addRequest);
return true;
}
return false;
}
private void button1_Click(object sender, EventArgs e)
{
IncluirUsuario();
}
o parametro está em branco, pq qualquer coisa que eu passar, vai dar erro.
There is no argument Given that Corresponds to the required formal Parameter "usuario"
Thanks in advance.
@G.Otanip did not understand very well, as I said I’m beginner, but I will post the class here and thank you for the response:
public sealed class Usuario
{
public string Nome = "TESTE";
public string Sobrenome = "CJ";
public string Email = "[email protected]";
public string Senha = "******";
}
The parameter you need to pass is an object of type
Usuario
. See the statement of this classUsuário
and how you can instantiate and fill it before calling the functionIncluirUsuario()
– g-otn
Dude I think I figured it out with the tip you gave me! I managed to instantiate.
– Anderson User777
Anderson, if you managed to resolve your question, I ask you to mark the question as solved, below the upvotes in the answers. Thanks.
– Robson Silva