gpt4 book ai didi

asp.net - 从 ASP.NET 应用程序使用 Active Directory 时出现 DirectoryServicesCOMException (0x80072020)

转载 作者:行者123 更新时间:2023-12-04 20:46:35 25 4
gpt4 key购买 nike

介绍
我正在维护一个查询 Active Directory 的旧版 ASP.NET 3.5 应用程序。该应用程序使用“集成 Windows 身份验证”,旨在使用其自己的安全上下文而不是专用的用户名和密码连接到 Active Directory。
这是相关的代码。

using (DirectoryEntry root = new DirectoryEntry())
using (DirectorySearcher searcher = new DirectorySearcher(root))
{
searcher.Filter = string.Format("(&(samAccountName={0})(objectClass=user)(objectCategory=person))", userName.Trim());
SearchResultCollection results = searcher.FindAll();
}
尽管它使用 ASP.NET 3.5,但由于现有基础结构限制,它需要可从 ASP.NET 4.0 应用程序池运行。
问题
调用 FindAll在某些情况下抛出以下异常:

System.DirectoryServices.DirectoryServicesCOMException (0x80072020): An operations error occurred.


当我使用 Visual Studio 调试器检查异常对象时, ExtendedErrorMessage属性包含更详细的信息:

000004DC: LdapErr: DSID-0C0906E8, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1


下面的屏幕截图显示了它在 Visual Studio 的调试器中的样子:
Image showing a DirectoryServicesCOMException with its ExtendedErrorMessage property set to 000004DC: LdapErr: DSID-0C0906E8, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1
什么有效
我找到了一些变通方法来完成这项工作,但我无法接受它们中的任何一个:
  • 禁用集成 Windows 身份验证,而是使用基本身份验证。
  • 在 IIS 中,在 ASP.NET 2.0 下运行应用程序并禁用网络服务帐户和 ASP.NET 模拟。
  • 仅从 Web 服务器访问应用程序,使用 localhost 作为主机名。
  • 将 ASP.NET 模拟与 web.config 中的硬编码帐户一起使用。

  • 什么不起作用
    我从互联网上找到了一些建议,但没有一个能完全解决问题:
  • 使用 HostingEnvironment.Impersonate() .
  • 禁用模拟。

  • 我想要的是
    我想让这项工作无需重新配置 Active Directory 中的任何内容。如上所示,它在某些 IIS 配置下工作正常,因此我相信应该可以通过重新配置应用程序或 IIS 使其工作(更改 .NET 框架版本除外)。

    最佳答案

    我认为问题有多种原因:

  • 使用 ASP.NET 模拟。
  • 在 ASP.NET 4.0 应用程序池下运行 ASP.NET 3.5 应用程序。

  • 要解决第二个问题,请将应用程序升级到 ASP.NET 4.0 或将 IIS 配置为使用 ASP.NET 2.0。

    关于asp.net - 从 ASP.NET 应用程序使用 Active Directory 时出现 DirectoryServicesCOMException (0x80072020),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17103066/

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