gpt4 book ai didi

asp.net - 在 ASP.NET 中访问 Active Directory?

转载 作者:行者123 更新时间:2023-12-02 13:46:13 24 4
gpt4 key购买 nike

我使用控制台应用程序编写一些测试代码:

    /// <summary>
/// Returns AD information for a specified userID.
/// </summary>
/// <param name="ntID"></param>
/// <returns></returns>
public ADUser GetUser(string ntID)
{
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(cn={0})", ntID);

search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("givenName");
search.PropertiesToLoad.Add("sn");
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("userPrincipalName");
search.PropertiesToLoad.Add("cn");

SearchResult result = search.FindOne();

return new ADUser(result);
}

这在控制台应用程序中运行良好。但是,当我将其移动到 ASP.NET 应用程序时,我收到一条关于不知道正确域的错误消息。

在 ASPNET 帐户上运行时,我是否缺少访问 AD 的技巧?

编辑:仅传递 LDAP://domain 连接字符串是不够的,因为它需要实际的登录名/密码。因为它在计算机上的本地帐户上运行,所以我不确定要使用什么 AD L/P。我可以以某种方式将访问用户帐户委托(delegate)给此帐户吗?

编辑#2:当尝试使用身份模拟时,我收到一个 DirectoryServicesCOMException:

身份验证机制未知。

最佳答案

是的。您需要给它一个目录连接字符串。控制台应用程序(与您一起运行)使用您的凭据运行,包括目录访问权限。 ASP.NET 应用程序使用 ASPNET 用户凭据运行,这些凭据是应用程序运行所在系统的本地凭据,而不是目录全局凭据。

关于asp.net - 在 ASP.NET 中访问 Active Directory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/350628/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com