views:

179

answers:

1

Hi,

I am working in a Login page and teh logic is like ->

try 
{
    DirectoryEntry LDAPLogin = new DirectoryEntry(ConfigurationSettings.AppSettings ["LDAPPath"].ToString(), Usuario, Txt_Contrasenia.Text.ToString());

    if (LDAPLogin.NativeGuid != LDAPLogin.Name)
       ValidarGrupo();
}
catch (Exception exc)
{
   Label_Info.Text = "Sus credenciales no son validas: " + Usuario.ToString() + " " + exc.Message;
}

If the user enters the rights credentials I call a method ValidarGrupo that implements a lookup in the AD for a group of the user

I would like to replace the username and password with UseDefaultCredentials in order to avoid that the user has to enter the username and password and the Login pages use the credentials of the user that is login on the machine.

A: 

I would like to replace the username and password with UseDefaultCredentials in order to avoid that the user has to enter the username and password and the Login pages use the credentials of the user that is login on the machine.

So you basically want to check whether the currently logged in user is valid?

I believe you can just simply create the DirectoryEntry without specifying any username/password - in that case, System.DirectoryServices will automatically use the current user credentials:

string ldapPath = ConfigurationSettings.AppSettings ["LDAPPath"];
DirectoryEntry LDAPLogin = new DirectoryEntry(ldapPath);

That should be enough, I believe!

marc_s
In that case do you know if I can extract the user from DirectoryEntry in other words the current user name
Copeleto