如何使iis中托管的wcf服务访问另一个服务器的活动目录

本文关键字:另一个 访问 服务器 活动 服务 wcf iis 何使 | 更新日期: 2023-09-27 18:29:00

如何使iis中托管的wcf服务访问另一个服务器活动目录

有2台服务器1-WCF服务托管在IIS上的应用程序服务器2-Active directory服务器我想做的就是让这个WCF访问活动目录来添加、编辑或删除用户

如何使WCF服务访问同一网络中另一台服务器的AD我正在开发intranet门户网站,用户可以使用他们的Windows凭据"AD"登录,并希望开发一个管理页面,将用户添加到"AD"

在"AD"中创建用户的wcf服务没有权限这样做,我怎么能这样做?

    public bool AddActiveDirectoryUser(ADUser User)
    {
        string userLoginName = User.Email.Split("@".ToArray())[0];
        // Creating the PrincipalContext
        PrincipalContext principalContext = null;
        try
        {
            principalContext = new PrincipalContext(ContextType.Domain, ADServer, ADPath.Substring(ADPath.IndexOf("DC")), ADUser, ADPassword);
        }
        catch (Exception e)
        {
            WriteLog(e);
            return false;
        }

        UserPrincipal usr = UserPrincipal.FindByIdentity(principalContext, userLoginName);
        if (usr != null)
        {
            WriteLog(Enum.LogType.Error, userLoginName + " already exists. Please use a different Username.");
            return false;
        }
        // Create the new UserPrincipal object
        UserPrincipal userPrincipal = new UserPrincipal(principalContext);
        if (!string.IsNullOrEmpty(User.LastName) && User.LastName.Length > 0)
            userPrincipal.Surname = User.LastName;
        if (!string.IsNullOrEmpty(User.FirstName) && User.FirstName.Length > 0)
            userPrincipal.GivenName = User.FirstName;
        if (!string.IsNullOrEmpty(User.Email) && User.Email.Length > 0)
            userPrincipal.EmailAddress = User.Email;

        if (!string.IsNullOrEmpty(userLoginName) && userLoginName.Length > 0)
            userPrincipal.SamAccountName = userLoginName;
        userPrincipal.SetPassword("123456");
        userPrincipal.Enabled = true;
        userPrincipal.PasswordNeverExpires = true;
        try
        {
            userPrincipal.Save();

//在这里它抛出了一个异常访问被拒绝!!!!?

        }
        catch (Exception e)
        {
            WriteLog(e);
            return false;
        }
        return true;
    }

如何使iis中托管的wcf服务访问另一个服务器的活动目录

好的,根据您提供的信息,问题如下。用于创建上下文的用户没有足够的权限来执行这些任务。您需要向该用户授予创建用户所在OU的权限,所有问题都应该解决。

查看此帖子以了解有关该主题的更多信息https://serverfault.com/questions/190566/what-permissions-are-needed-for-a-helpdesk-admin-to-create-users-in-ad