C# 用户主体始终为空
我使用域域A下的用户User001登录,密码为Pass001 我使用这个代码C# 用户主体始终为空,c#,.net,principalcontext,C#,.net,Principalcontext,我使用域域A下的用户User001登录,密码为Pass001 我使用这个代码 //var principalContext = new PrincipalContext( //ContextType.Domain, //"DomainA", //"User001", //"Pass001"); var principalContext = new PrincipalContext( ContextType.Domain, domain, use
//var principalContext = new PrincipalContext(
//ContextType.Domain,
//"DomainA",
//"User001",
//"Pass001");
var principalContext = new PrincipalContext(
ContextType.Domain,
domain,
userName,
password);
var userPrincipal = new UserPrincipal(principalContext);
并且userPrincipal
始终为空
如何修复它?不知怎的,我发现这段代码运行得很好
using (var context = new PrincipalContext(ContextType.Domain))
{
using (UserPrincipal principal = UserPrincipal.FindByIdentity(context, userName))
{
var uGroups = principal.GetGroups();
foreach (var group in uGroups)
{
Debug.WriteLine(group.DisplayName);
}
}
}
问题还不清楚,你能提供更多的代码和上下文吗?