gpt4 book ai didi

c# - IIS7 上的 DirectoryServicesCOMException 与 System.DirectoryServices.AccountManagement 但不是在开发中

转载 作者:太空宇宙 更新时间:2023-11-03 16:26:57 25 4
gpt4 key购买 nike

以下代码在我的开发 PC 上运行良好,但在部署到服务器时崩溃:

using System.DirectoryServices.AccountManagement;

using (var ctx = new PrincipalContext(ContextType.Domain, domainName))
using (GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, groupName))
{
if (grp == null) return new string[0];

return grp.GetMembers(true).Select(m => m.SamAccountName).ToArray();
}

崩溃如下:

[DirectoryServicesCOMException (0x80072020): An operations error occurred.]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +439513
System.DirectoryServices.DirectoryEntry.Bind() +36
System.DirectoryServices.DirectoryEntry.get_AdsObject() +31
System.DirectoryServices.PropertyValueCollection.PopulateList() +22
System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +96
System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +141
System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() +1134
System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() +37
System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() +124
System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() +31
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) +14
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue) +86
System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) +29
WebApp.WebForm1.Test() in C:\MyProject\trunk\WebApp\WebForm1.aspx.cs:30

场景:

  • 加入域的 Windows Server 2008 x64 上的 IIS7
  • ASP.NET 4 内联网应用
  • 在 IIS 中关闭除集成 Windows 身份验证之外的所有身份验证模式
  • 配置为以域用户身份运行的应用程序池

Web.config 如下:

<authentication mode="Windows" />
<authorization>
<deny users="?"/>
</authorization>
<identity impersonate="true" >

System.Security.Principal.WindowsIdentity.GetCurrent().Name 在生产环境中正确返回我的 AD 用户名,所以我认为这意味着模拟工作正常。

最佳答案

我遇到了类似的问题。

我在网络服务器上部署后才收到此错误,它在我的机器上运行完美。

我发现,在服务器上,在 IIS 中,模拟仍然通过窗口身份验证进行检查。

并且通过在 IIS 中删除这个模拟,错误消失了......

关于c# - IIS7 上的 DirectoryServicesCOMException 与 System.DirectoryServices.AccountManagement 但不是在开发中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12265753/

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