el siguiente código funcionaba durante 3 meses sin ningún problema. Desde hoy recibo el siguiente error; "Excepción ha sido lanzada por el objetivo de una invocación" y la excepción interna; . "Acceso denegado (Excepción de HRESULT: 0x80070005 (E_ACCESSDENIED)"LDAP SetPassword Acceso denegado
funciona La función de autenticación Aquí están mis funciones;
public bool Authenticate(string strUserName, string strPassword)
{
bool authenticated = false;
using (
var entry = new DirectoryEntry("LDAP://myldapserver", strUserName + "@domain", strPassword,
AuthenticationTypes.Secure))
{
try
{
object nativeObject = entry.NativeObject;
authenticated = true;
}
catch (DirectoryServicesCOMException ex)
{
return false;
}
}
return authenticated;
}
y el método ChangePassword;
public bool ChangePassword(string strUserName, string strOldPassword, string strNewPassword)
{
const long ADS_OPTION_PASSWORD_PORTNUMBER = 6;
const long ADS_OPTION_PASSWORD_METHOD = 7;
const int ADS_PASSWORD_ENCODE_REQUIRE_SSL = 0;
const int ADS_PASSWORD_ENCODE_CLEAR = 1;
string strPort = "636";
int intPort;
intPort = Int32.Parse(strPort);
try
{
string strUserString = "domain" + @"\" + strUserName.Trim();
var entry = new DirectoryEntry("LDAP://myldapserver", strUserString, strOldPassword,
AuthenticationTypes.Secure);
var search = new DirectorySearcher(entry);
string strFilter = "(SAMAccountName=" + strUserName + ")";
search.Filter = strFilter;
SearchResult result = search.FindOne();
DirectoryEntry user = result.GetDirectoryEntry();
user.Invoke("SetOption", new object[] { ADS_OPTION_PASSWORD_PORTNUMBER, intPort });
user.Invoke("SetOption", new object[] { ADS_OPTION_PASSWORD_METHOD, ADS_PASSWORD_ENCODE_CLEAR });
**user.Invoke("SetPassword", new object[] { strNewPassword });**
user.CommitChanges();
user.Close();
}
catch (Exception exception)
{
string msg = exception.InnerException.Message;
return false;
}
return true;
}
Se lanza la expceción cuando invoco la propiedad SetPassword. Cualquier ayuda sería muy apreciada.
¿Qué línea está fallando? ¿Qué método está fallando? –
ChangePassword es el que falla en la línea user.Invoke ("SetPassword", new object [] {strNewPassword}); – user1595357
El mensaje que publicó en la parte superior, ¿es esa la excepción interna? Lo pregunto porque la excepción interna contiene la excepción actual de COM recibida. –