1

我正在尝试在 Windows Server 2008 R2(安装了 IIS7)上运行的 ASP.Net (4.0) 应用程序中查询 AD。在我的本地计算机(Windows 7)上运行良好,但在服务器上运行良好。我正在尝试获取当前用户的用户 ID。我看过类似问题的问答,但没有成功。

这是代码片段...

public partial class Default : System.Web.UI.Page
    {
        PrincipalContext principalCtx = new PrincipalContext(ContextType.Domain);
        UserPrincipal currentUser = UserPrincipal.Current;

web.config 有

<authentication mode="Windows"/>
<identity impersonate="true" />

这是错误和堆栈跟踪...

[DirectoryServicesCOMException (0x80072020): An operations error occurred.
]
   System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +781
   System.DirectoryServices.DirectoryEntry.Bind() +44
   System.DirectoryServices.DirectoryEntry.get_AdsObject() +42
   System.DirectoryServices.PropertyValueCollection.PopulateList() +29
   System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +119
   System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +163
   System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() +541617
   System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() +51
   System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() +141
   System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() +42
   System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) +27
   System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue) +146
   System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) +44
   System.DirectoryServices.AccountManagement.UserPrincipal.get_Current() +390

我尝试将 IIS 应用程序池作为 NetworkService 和 ApplicationPoolIdentity 运行,但效果不佳。

有任何想法吗?谢谢。

4

0 回答 0