c#-3.0 - 使用默认凭据来调用 DirectoryEntry

标签 c#-3.0 active-directory authentication

我正在登录页面工作,逻辑就像 ->

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/

相关文章:

c#-3.0 - 如何从 TreeNode.FullPath 数据获取实际的树节点?

c#-3.0 - 为什么我不能用 Moq 模拟 MouseButtonEventArgs.GetPosition()?

powershell - 如何在Active Directory组中填写Notes属性?

c++ - 在输入错误的密码时锁定应用程序 (c/c++)

javascript - 身份验证后使用 Javascript SDK 重定向 URI

c#-3.0 - C#中简化丑陋嵌套if-else树的方法

c#-3.0 - 是否可以将 C# 对象初始值设定项与工厂一起使用

powershell - Get-ADGroupMember停止为某些用户工作

sql-server - 重命名AD中的安全组,并映射SQL登录

authentication - Azure 事件目录 : ACS50000: There was an error issuing a token