我正在编写一个web服务,它检查用户是否存在于Active Directory中,以及用户帐户是否已启用。一旦检查完毕,我将继续验证他们的用户帐户。一旦他们成功地输入用户名和密码,我想为我认证的人获得GUID或NativeGuid。我希望使用GUID或NativeGUID在Server数据库中构建关系。
下面是我采取的方法:
public string isAuthenticated (string serverName, string userName, string pwd)
{
string _serverName, _userName, _pwd;
_serverName = serverName;
_userName = userName;
_pwd = pwd;
string message;
if (DoesUserExist (_userName) == true)
{
if (isActive(userName) == true)
{
try
{
DirectoryEntry entry = new DirectoryEntry(_serverName, _userName, _pwd);
object nativeObject = entry.NativeObject;
//issue is here
string GUID = entry.Guid.ToString();
string GUIDID = entry.NativeGuid;
//end of issue
message = "Successfully authenticated";
}
catch(DirectoryServicesCOMException ex)
{
message = ex.Message;
}
}
else
{
message = "Account is disabled";
}
}
else
{
message = "There's an issue with your account.";
}
return message;
}当我尝试获取GUID或NativeGUID时,它每次都为不同的用户返回相同的ID。
对于Active Directory中的不同对象,有什么不同的方法可以获得UNIQUE ID吗?
谢谢
发布于 2014-12-12 16:32:55
如果您使用的是.NET 3.5或更高版本,则应该查看System.DirectoryServices.AccountManagement (S.DS.AM)命名空间。在这里读到所有的内容:
基本上,您可以定义域上下文并在AD中轻松找到用户和/或组:
// set up domain context
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, _userName);
if(user != null)
{
// get the GUID
var objectGuid = user.Guid;
}
}新的S.DS.AM使得在AD中与用户和组玩真的很容易!我现在没有一个AD可以用来测试--但我希望这确实会给出用户对象的objectGuid属性值。
https://stackoverflow.com/questions/27447823
复制相似问题