Urgent Regarding Directoryentry.Invoke(Setpassword,"") method
-
I have a very typical problem. I am trying to create a user in activedirectory running in windows 2003 server. i am able to create user but when coming to setting password its not working. the code : String strPath = "LDAP://192.168.0.101:389/OU=100001,DC=Tserver,DC=local"; try { DirectoryEntry user = new DirectoryEntry(strPath, @"Tserver.local\administrator", "password", AuthenticationTypes.Secure | AuthenticationTypes.Sealing |AuthenticationTypes.ServerBind ); //create user DirectoryEntry user = entry.Children.Add("cn=Test User", "user"); user.Properties["sAMAccountName"].Add("testuser"); user.Properties["sn"].Add("User"); user.Properties["givenName"].Add("Test"); user.Properties["description"].Add("Test account added with code."); user.CommitChanges(); // User has to be saved prior to this step user.Invoke("SetPassword", new string[] {"password1"} ); user.CommitChanges(); user.Close(); user.Dispose(); } catch (Exception exx) { Response.Write("Exception: "+ exx.ToString() + " \n"); return; } Response.Write("Success: Password set."); Error Description: 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.IO.FileNotFoundException: The network path was not found. Source Error: Line 127: Line 128: // User has to be saved prior to this step Line 129: user.Invoke("SetPassword", new string[] {"princeton"} ); Line 130: user.Properties["userAccountControl"].Value = 0x200; Line 131: user.CommitChanges(); Source File: c:\inetpub\wwwroot\adminlogin\pages\information.aspx.cs Line: 129 Stack Trace: [FileNotFoundException: The network path was not found.] [TargetInvocationException: Exception has been thrown by the target of an invocation.] 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) AdminLogin.Information.btnSave_Click(Object sender, EventArg
-
I have a very typical problem. I am trying to create a user in activedirectory running in windows 2003 server. i am able to create user but when coming to setting password its not working. the code : String strPath = "LDAP://192.168.0.101:389/OU=100001,DC=Tserver,DC=local"; try { DirectoryEntry user = new DirectoryEntry(strPath, @"Tserver.local\administrator", "password", AuthenticationTypes.Secure | AuthenticationTypes.Sealing |AuthenticationTypes.ServerBind ); //create user DirectoryEntry user = entry.Children.Add("cn=Test User", "user"); user.Properties["sAMAccountName"].Add("testuser"); user.Properties["sn"].Add("User"); user.Properties["givenName"].Add("Test"); user.Properties["description"].Add("Test account added with code."); user.CommitChanges(); // User has to be saved prior to this step user.Invoke("SetPassword", new string[] {"password1"} ); user.CommitChanges(); user.Close(); user.Dispose(); } catch (Exception exx) { Response.Write("Exception: "+ exx.ToString() + " \n"); return; } Response.Write("Success: Password set."); Error Description: 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.IO.FileNotFoundException: The network path was not found. Source Error: Line 127: Line 128: // User has to be saved prior to this step Line 129: user.Invoke("SetPassword", new string[] {"princeton"} ); Line 130: user.Properties["userAccountControl"].Value = 0x200; Line 131: user.CommitChanges(); Source File: c:\inetpub\wwwroot\adminlogin\pages\information.aspx.cs Line: 129 Stack Trace: [FileNotFoundException: The network path was not found.] [TargetInvocationException: Exception has been thrown by the target of an invocation.] 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) AdminLogin.Information.btnSave_Click(Object sender, EventArg
99% of the time....when you get a System.Exception.FileNotFound it is due to the fact that you are trying to get an assembly and that assembly either does not exist on the target machine ... or it does exist but the assembly identifiers do not match. For example: if you built your application and used System.Security.dll which had an assembly identifier of version 1.1.4322 but a service pack that your machine did not receive had version System.Security.dll at version 1.1.4325 then you would get that exception. This signature left intentionally blank
-
I have a very typical problem. I am trying to create a user in activedirectory running in windows 2003 server. i am able to create user but when coming to setting password its not working. the code : String strPath = "LDAP://192.168.0.101:389/OU=100001,DC=Tserver,DC=local"; try { DirectoryEntry user = new DirectoryEntry(strPath, @"Tserver.local\administrator", "password", AuthenticationTypes.Secure | AuthenticationTypes.Sealing |AuthenticationTypes.ServerBind ); //create user DirectoryEntry user = entry.Children.Add("cn=Test User", "user"); user.Properties["sAMAccountName"].Add("testuser"); user.Properties["sn"].Add("User"); user.Properties["givenName"].Add("Test"); user.Properties["description"].Add("Test account added with code."); user.CommitChanges(); // User has to be saved prior to this step user.Invoke("SetPassword", new string[] {"password1"} ); user.CommitChanges(); user.Close(); user.Dispose(); } catch (Exception exx) { Response.Write("Exception: "+ exx.ToString() + " \n"); return; } Response.Write("Success: Password set."); Error Description: 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.IO.FileNotFoundException: The network path was not found. Source Error: Line 127: Line 128: // User has to be saved prior to this step Line 129: user.Invoke("SetPassword", new string[] {"princeton"} ); Line 130: user.Properties["userAccountControl"].Value = 0x200; Line 131: user.CommitChanges(); Source File: c:\inetpub\wwwroot\adminlogin\pages\information.aspx.cs Line: 129 Stack Trace: [FileNotFoundException: The network path was not found.] [TargetInvocationException: Exception has been thrown by the target of an invocation.] 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) AdminLogin.Information.btnSave_Click(Object sender, EventArg
shambho wrote: // User has to be saved prior to this step user.Invoke("SetPassword", new string[] {"password1"} ); Your should be passing an
Object[]
instead:Object[] pswd = new Object[]{"password1"};
However by default all code that executes from the local intranet or Internet zones is partially trusted and full trust is required. You might check into placing the
AllowPartiallyTrustedCallers
attribute on your code. - Nick Parker
My Blog | My Articles -
99% of the time....when you get a System.Exception.FileNotFound it is due to the fact that you are trying to get an assembly and that assembly either does not exist on the target machine ... or it does exist but the assembly identifiers do not match. For example: if you built your application and used System.Security.dll which had an assembly identifier of version 1.1.4322 but a service pack that your machine did not receive had version System.Security.dll at version 1.1.4325 then you would get that exception. This signature left intentionally blank
But my dear friend i am able to create user add all other properties why not password. Is this System.Security.dll has some thing to do with setpassword native method alone. I dont know thats why i am posting this reply. Kindly reply me thanks in advance anand
-
shambho wrote: // User has to be saved prior to this step user.Invoke("SetPassword", new string[] {"password1"} ); Your should be passing an
Object[]
instead:Object[] pswd = new Object[]{"password1"};
However by default all code that executes from the local intranet or Internet zones is partially trusted and full trust is required. You might check into placing the
AllowPartiallyTrustedCallers
attribute on your code. - Nick Parker
My Blog | My Articleshi friend, actually i am not using user.Invoke("SetPassword", new string[] {"password1"} ); but user.Invoke("SetPassword", new object[] {"password1"} ); By mistake while i was trying different alternative you got this piece of code. even with object its giving the same error