我正在登录页面工作,逻辑就像 ->
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;
}
如果用户输入权限凭据,我将调用 ValidarGrupo 方法,该方法在 AD 中实现对用户组的查找
我想用 UseDefaultCredentials 替换用户名和密码,以避免用户必须输入用户名和密码,并且登录页面使用在计算机上登录的用户的凭据。
最佳答案
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.
所以您主要是想检查当前登录的用户是否有效?
我相信您可以简单地创建 DirectoryEntry 而无需指定任何用户名/密码 - 在这种情况下,System.DirectoryServices
将自动使用当前用户凭据:
string ldapPath = ConfigurationSettings.AppSettings ["LDAPPath"];
DirectoryEntry LDAPLogin = new DirectoryEntry(ldapPath);
我相信这应该足够了!
关于c#-3.0 - 使用默认凭据来调用 DirectoryEntry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2595826/