FindByIdentity未能与PricipalOperationException在ASP.NET Web应用程序 [英] FindByIdentity failing with PricipalOperationException in ASP.NET webapp

查看:167
本文介绍了FindByIdentity未能与PricipalOperationException在ASP.NET Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,在我的内部Web应用程序使用System.DirectoryServices.AccountManagement挣扎。该错误是不是很描述性的,但在这里发生了什么:

I'm struggling with an issue in utilizing System.DirectoryServices.AccountManagement in my internal web application. The error is not very descriptive, but here's what's going on:

当我尝试验证所提供的用户ID存在于公元,我这样做有以下code:

When I attempt to validate that a provided user id exists in the AD, I do so with the following code:

private bool IsWindowsIDValid(string strWindowsID) 
{ 
var context = new PrincipalContext(ContextType.Domain, "DOMAINSERVER", "DC=DOMAINNAME,DC=net"); 
var userPrincipal = UserPrincipal.FindByIdentity(context, strWindowsID); 
return (userPrincipal != null); 
}

然而,一个例外是扔在第二行,其中FindByIdentity被调用。下面是异常详细信息:

However, an exception is throw at the second line, where FindByIdentity is called. Here are the exception details:

消息: 发生操作错误。

Message: "An operations error occurred."

堆栈跟踪:

在System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit() 在System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() 在System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() 在System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() 在System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext背景下,类型principalType,Nullable`1 identityType,串identityValue,日期时间refDate) 在System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext背景下,类型principalType,字符串identityValue) 在System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext背景下,字符串identityValue) 位于 .IsWindowsIDValid(字符串strWindowsID)中的 .ascx.cs:行193

at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit() at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, String identityValue) at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, String identityValue) at .IsWindowsIDValid(String strWindowsID) in .ascx.cs:line 193

如果我试图检查PrincipalContext的ConnectedServer性以及会发生此相同的错误。不过,我可以尝试验证凭据对上下文(使用context.ValidateCredentials()),它会通过就好了。

This same error occurs if I attempt to examine the ConnectedServer property of the PrincipalContext as well. However, I can attempt to validate credentials against the context (using context.ValidateCredentials()), and it will pass just fine.

任何想法,以什么可以怎么回事?我可以在我的机器上运行此code就好在独立主机的脚本 - 这是发生在我的本地开发环境,里面的VisualStudio,当我试图调试Web应用程序。这是一个权限问题还是其他什么东西吧?我是pretty的在这一点上失去了。

Any ideas as to what may be going on? I can run this code just fine in a stand alone console script on my machine - this is occurring in my local development environment, inside VisualStudio, when I attempt to debug the webapp. Is this a permissions issue or something else perhaps? I'm pretty lost at this point.

我AP preciate任何帮助!

I appreciate any help!

-Patrick

推荐答案

这是老问题,但我有同样的错误。对我来说,问题是, PrincipalContext 不无它的构造一个用户名和密码的工作......我得到确切同样的错误消息,每当我调用任何方法或属性的 UserPrincipal (或在 PrincipalContext 为此事)。

An old question, but I had this same error. For me, the problem is that PrincipalContext doesn't work without a username and password in its constructor... I get the exact same error message whenever I call any method or property of the UserPrincipal (or on the PrincipalContext for that matter).

如果您指定与Active Directory权限你指定容器中的域用户的用户名和密码,调用 FindByIdentity 应该会成功:

If you specify a username and password of a domain user with Active Directory permissions to the container you're specifying, the call to FindByIdentity should succeed:

var context = new PrincipalContext(ContextType.Domain, "DOMAINSERVER",
                                   "DC=DOMAINNAME,DC=net", userName, pw); 
var userPrincipal = UserPrincipal.FindByIdentity(context, strWindowsID); 

对于我来说,这不是一个解决方案,因为我不会让这两个参数。但是,这就是为什么你要你得到的错误。

For me, this isn't a solution, because I won't have those two parameters. But that's why you're getting the error you're getting.

据微软的帮助下,做你的方式应该在调用进程的凭据来运行......但不管我下运行谁(我已经验证了模拟)调用一个 UserPrincipal 的对象,而无需指定其 PrincipalContext 是行不通的用户名和PW。

According to Microsoft's help, doing it your way should run under the credentials of the calling process... but no matter who I'm running under (and I've verified the impersonation) calls to a UserPrincipal object without specifying a username and pw on its PrincipalContext just won't work.

希望这迟来的帮助, 詹姆斯

Hope that belatedly helps, James

这篇关于FindByIdentity未能与PricipalOperationException在ASP.NET Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆