我有一个页面可以使用VB.NET在我们的活动目录中创建新用户 我正在使用以下代码
Dim rootEntry As New DirectoryEntry
With rootEntry
.Path = "LDAP://" & strServer & "/" & strLDAP
.AuthenticationType = AuthenticationTypes.Secure
.Username = strServerUsername
.Password = strServerPassword
End With
Dim newUser As DirectoryEntry = rootEntry.Children.Add("CN=" & strCN, "user")
With newUser
.CommitChanges()
.Properties("userPrincipalName").Value = TextPN.Text
.Properties("sAMAccountName").Value = TextAlias.Text
.Properties("givenname").Value = TextGivenname.Text
.Properties("sn").Value = TextSurname.Text
……
.CommitChanges()
.Invoke("setPassword", New Object() {strDefaultPassword})
.CommitChanges()
.Properties("userAccountControl").Value = &H0001
.CommitChanges()
End With
此代码在过去运作良好。 现在我们已经将我们的Web服务器迁移到Windows Server 2008 R2和IIS 7.5,突然代码不再起作用了。 (.net框架是2.0,无法更改) 用户仍在我们的活动目录中创建,但帐户被自动禁用,密码未设置。
调查此问题表明在行
处抛出异常 .Invoke("setPassword", New Object() {strDefaultPassword})
异常
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
用于连接到AD的用户帐户仍然相同,并具有域管理员权限。 由于没有任何改变代码,我认为必须有另一个原因,为什么这不再工作?防火墙设置,IIS配置,..?
任何想法??
我知道这里有一个类似的案例Trying to create a new Active Directory user, Invoke("SetPassword",pwd) throws "The RPC server is unavailable" ,但这对我没有帮助。
答案 0 :(得分:1)
检查防火墙上是否打开了TCP / UDP 445端口。 要从域外连接到AD服务器,您需要打开以下端口: 。 TCP / UDP 389(LDAP) 。 TCP 3268(GC) 。 TCP / UDP 445(基于IP的SMB)
答案 1 :(得分:1)
DirectoryEntry.Invoke()需要AuthenticationType.Secure。这意味着它需要能够通过Kerberos或NTLM验证请求。
它首先尝试使用LDAPS(TCP 636),然后在由于证书丢失或无效而超时或失败时回退到CiFS(TCP445)。如果这些端口都未打开,则会因“RPC服务器不可用”异常而失败。