Re: change password in active directory by webapplication (vb.net)
From: Joe Kaplan \(MVP - ADSI\) (joseph.e.kaplan_at_removethis.accenture.com)
Date: 04/26/04
- Next message: Jonathan wax: "Automaticall Signout after no activity..."
- Previous message: Bigtoga: "Re: Can I force 401 error when user not authenticated?"
- In reply to: Sara rafiee: "Re: change password in active directory by webapplication (vb.net)"
- Next in thread: Sara rafiee: "Re: change password in active directory by webapplication (vb.net)"
- Reply: Sara rafiee: "Re: change password in active directory by webapplication (vb.net)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Mon, 26 Apr 2004 12:44:49 -0500
It is not clear to me from your code that you have bound to an actual user
object to change a password on.
You need to either know the distinguished name of the use you want to change
the password on and bind to that username or you need to create a search to
find the user by some other known criteria. The code for the former would
look something like:
'you need to supply a valid path to a user and valid admin credentials to
set the password
Try
Dim entry As DirectoryEntry = New
DirectoryEntry("LDAP://Hosnieh_Rafiee/cn=someone,cn=users,dc=yourdomain,dc=c
om", adminUsername, adminPassword, AuthenticationTypes.Secure)
Dim bindCheck As Object = entry.NativeObject
entry.Invoke("setPassword", New Object() {"newpassword"})
entry.CommitChanges()
Finally
If Not entry is Nothing then entry.Dispose()
End Try
Note that the Invoke method throws a TargetInvocationException, so if you
want to get the actual exception thrown, you need to check the
InnerException property to get the COMException.
Explain more what you are trying to do and I can probably help more.
Joe K.
"Sara rafiee" <sara_ir110@yahoo.com> wrote in message
news:uDzlVQ3KEHA.1156@TK2MSFTNGP09.phx.gbl...
> Hi
> this is my error on my code for changing user password in active
> directory programmatically
> Inherits System.Web.UI.Page
> Protected WithEvents newpass As System.Web.UI.WebControls.TextBox
> Protected WithEvents btn1 As System.Web.UI.WebControls.Button
> Protected WithEvents username As System.Web.UI.WebControls.TextBox
> Protected WithEvents txt2 As System.Web.UI.WebControls.TextBox
> Protected WithEvents txt1 As System.Web.UI.WebControls.TextBox
> Protected WithEvents btn2 As System.Web.UI.WebControls.Button
> Protected WithEvents oldpass As System.Web.UI.WebControls.TextBox
> Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btn1.Click
> Dim dom As DirectoryEntry = New
> DirectoryEntry("LDAP://Hosnieh_Rafiee", "Hosnieh_Rafiee\admin11", "bbb")
>
> Dim entry As DirectoryEntry = New
> DirectoryEntry("LDAP://Hosnieh_Rafiee", username.Text, oldpass.Text)
> Dim search As New DirectorySearcher(entry)
>
> Dim result As SearchResult = search.FindOne
>
> 'If entry.Password = oldpass.Text Then
> Dim b As String
>
> entry.Invoke("setPassword", "newpassword")
> entry.CommitChanges()
>
> Response.Write(entry.Password)
>
> Response.Write("successful")
>
> 'Else
> ' Response.Write("your username or password is incorrect")
> 'End If
> End Sub
>
> Server Error in '/netaccount' Application.
> ------------------------------------------------------------
>
> The Active Directory property cannot be found in the cache.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.Runtime.InteropServices.COMException: The
> Active Directory property cannot be found in the cache.
>
> Source Error:
>
>
> Line 42: Dim b As String
> Line 43:
> Line 44: entry.Invoke("setPassword", "newpassword")
> Line 45: entry.CommitChanges()
> Line 46:
>
>
> Source File: g:\My Documents\Visual Studio
> Projects\netaccount\WebForm1.aspx.vb Line: 44
>
> Stack Trace:
>
>
> [COMException (0x80020006): The Active Directory property cannot be
> found in the cache.
> ]
> System.RuntimeType.InvokeDispMethod(String name, BindingFlags
> invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
> Int32 culture, String[] namedParameters) +0
> System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr,
> Binder binder, Object target, Object[] args, ParameterModifier[]
> modifiers, CultureInfo culture, String[] namedParameters) +473
> System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder
> binder, Object target, Object[] args) +29
> System.DirectoryServices.DirectoryEntry.Invoke(String methodName,
> Object[] args)
> netaccount.WebForm1.btn1_Click(Object sender, EventArgs e) in g:\My
> Documents\Visual Studio Projects\netaccount\WebForm1.aspx.vb:44
> System.Web.UI.WebControls.Button.OnClick(EventArgs e)
>
> System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.Rai
> sePostBackEvent(String eventArgument)
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
> sourceControl, String eventArgument)
> System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
> System.Web.UI.Page.ProcessRequestMain()
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
- Next message: Jonathan wax: "Automaticall Signout after no activity..."
- Previous message: Bigtoga: "Re: Can I force 401 error when user not authenticated?"
- In reply to: Sara rafiee: "Re: change password in active directory by webapplication (vb.net)"
- Next in thread: Sara rafiee: "Re: change password in active directory by webapplication (vb.net)"
- Reply: Sara rafiee: "Re: change password in active directory by webapplication (vb.net)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]