我最近已从Windows机器移至Mac,并在ASP.Net Core中进行开发。
在Windows计算机上测试用户时,当前我使用以下代码:
User LookupAdUser(String logon)
{
if (String.IsNullOrEmpty(logon))
return null;
User user = null;
string domain = Environment.UserDomainName;
PrincipalContext ctx = null;
try
{
int index = logon.IndexOf(@"\");
if (index > 0)
{
// a domain has been specified so get information from that domain
domain = logon.Substring(0, index);
logon = logon.Substring(index + 1);
ctx = new PrincipalContext(ContextType.Domain, domain);
}
else
{
ctx = new PrincipalContext(ContextType.Domain);
}
UserPrincipal principal = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, logon);
if (principal != null)
{
user = new User
{
Logon = String.Format(@"{0}\{1}", domain, logon),
Email = principal.EmailAddress,
UserName = principal.EmailAddress,
EmailConfirmed = true,
Active = true
};
}
}
catch (Exception ex)
{
//Logger.Error(string.Format("Failed to lookup the user ({0}) in AD...creating an empty User object", logon), ex);
Debug.WriteLine(ex);
}
finally
{
if (ctx != null)
ctx.Dispose();
}
return user;
}
当移至Macbook并测试相同的代码时,出现错误:
Exception thrown: 'System.PlatformNotSupportedException' in System.DirectoryServices.AccountManagement.dll
mac os是否仍可以进入活动目录,对此有何解决方法?还是在Mac上无法做到?