0
我知道這是醜陋的,我知道我應該試試塊,我只是在試圖讓它工作。我在這裏錯過了一些東西,我真的很感激一些幫助。我所要做的就是創建一個包含登錄名稱文本框的頁面,以及一個用於舊密碼和兩個用於新密碼的頁面。要添加更多信息,我現在得到的錯誤是 未知名稱。 (異常來自HRESULT:0x80020006(DISP_E_UNKNOWNNAME)) 當我嘗試調用ChangePasswordASP.NET更改AD密碼
Dim userid As String
Dim password As String
Dim login As String
Dim check As String
login = txtLogin.Text
userid = txtLogin.Text
password = txtOldPass.Text
Dim entry As DirectoryEntry = New DirectoryEntry("LDAP://OU=PaidUsers,DC=LOCAL,DC=bb", "LOCAL\" & userid, password)
Dim obj As Object = entry.NativeObject
Dim search As DirectorySearcher = New DirectorySearcher(entry)
search.SearchScope = SearchScope.Subtree
search.Filter = "(SAMAccountName=" & login & ")"
Dim result As SearchResult = search.FindOne()
check = CType(result.Properties("sAMAccountName")(0), String)
If check = login Then
If txtNewPass.Text = txtNewPass2.Text Then
entry = result.GetDirectoryEntry()
entry.Username = "LOCAL\" & check
entry.Password = txtOldPass.Text
entry.AuthenticationType = AuthenticationTypes.Secure
entry.Options.Referral = ReferralChasingOption.All
entry.Invoke("ChangePassword", txtOldPass.Text, txtNewPass.Text)
entry.CommitChanges()
lblSuccess.Visible = True
Else
lblPasswdError.Visible = True
End If
Else
lblError.Visible = True
End If
我能夠通過結合一系列不同項目的解決方案最終弄清楚這個代碼,但我仍然知道並相信它需要大幅度清理。我只是認爲這可以幫助別人解決同樣的問題。解決方案代碼已更改爲上述代碼。 – JTuman
鼓勵自問自答!隨意發表您的評論作爲答案。 –