我有一个严重依赖AD身份验证的ASP.NET应用程序。我们最近爆发了一种服务,该服务过去与应用程序一起生活在它自己的解决方案中,以便我们能够单独维护它们,而不会影响依赖服务的用户,比如说,我们需要更改代码影响了应用程序的用户界面。检索AD组成员身份失败调试远程调用
虽然这给我带来了一个有趣的问题。当我调试时,我有我的本地应用程序副本指向服务的远程实例,该应用程序的环境副本也使用该实例。当我尝试使用本地应用程序验证用户的会员 - >调用远程服务时,出现以下异常:
System.Runtime.InteropServices.COMException(0x8007200A):该 指定的目录服务属性或值不不存在。
在System.DirectoryServices.DirectoryEntry.Bind(布尔 throwIfFail)在System.DirectoryServices.DirectoryEntry.Bind()
在System.DirectoryServices.DirectoryEntry.get_SchemaEntry()在 System.DirectoryServices.AccountManagement.ADStoreCtx.IsContainer (的DirectoryEntry 日)在 System.DirectoryServices.AccountManagement.ADStoreCtx..ctor(的DirectoryEntry ctxBase,布尔ownCtxBase,字符串username,字符串密码, ContextOptions选项)在 System.DirectoryServices.AccountManagement.PrincipalContext.CreateContextFromDirectoryEntry(的DirectoryEntry 进入)在 System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() 在 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.UserPrincipal.FindByIdentity(PrincipalContext 上下文,字符串identityValue)在 ******************。******************。**** **************。IsUserMemberOfGroup(String userName,String groupName)
当我尝试在同一组中验证同一用户,但使用Web浏览器来击中在遥控盒上的应用程序,然后点击远程服务,它作为一个蛤蜊感到高兴。
我使用的代码似乎非常简单。它必须与我的机器如何呼叫有关,但如果我可以解决问题,我会被贬低。
public static bool IsUserMemberOfGroup(string userName, string groupName)
{
try
{
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "XXX");
var user = GetUser(userName, ctx);
if (user == null)
{
Log4NetLogManager.LogError("Unable to find user " + userName);
return false;
}
// find the group in question
groupName = groupName.Replace("XXX\\", string.Empty);
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, groupName);
if (group != null) return user.IsMemberOf(group);
Log4NetLogManager.LogError("Unable to find group " + groupName);
return false;
}
catch (Exception ex)
{
if (!ex.Message.Contains("Unknown error"))
{
Log4NetLogManager.LogException(string.Format("Error while checking if {0} is a member of {1}", userName, groupName), ex);
}
return false;
}
}
private static UserPrincipal GetUser(string userName, PrincipalContext ctx)
{
UserPrincipal user = null;
userName = userName.Replace("XXX\\", string.Empty);
try
{
user = UserPrincipal.FindByIdentity(ctx, userName);
}
catch
{
}
return user ?? UserPrincipal.FindByIdentity(ctx, userName);
}
你是否在两种环境中检查你的.config文件?有什么区别? – JCM
是 - 唯一的区别是环境特定的(即电子邮件主题,目标,记录位置等)。 – Marisa
你检查了这个:http://stackoverflow.com/questions/29647024/the-specified-directory-service-attribute-or-value-does-not-exist? – JCM