Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

“Exception has been thrown by the target of an invocation” Is the code line for “SetPassword” as detail below is still valid on Active Directory in window 2012 R2?

$
0
0

First of all My web application has developed for user/group management  in active directoy as web services. It has been deployed on active directory on window server 2003 as well as run with .NET Framework 2.0. Our active directory is based on window server 2003 and is the same location as web application.   

Right now, we need to upgrade active directory from  window server 2003   to window server 2012 R2. Firstly , we add addition active directory that will be the same domain as existing active directory on window server 2003 and move web application to window server 2012  and point web application to newly created additional active directory on window server 2012 instead.

The main problem is that the code as below which is responsible for resetting password couldn’t apply to active directory on window server 2012 anymore . Initially I assume that the web application on IIS may not have permission to perform this action so we try to change a couple of configuration in web.config as the follows.

  • Run the AppPool under a user that has the required permissions
  • Use impersonation to elevate the permissions for the SetPassword call

But there is nothing happen, error still occur

The following show you below.

publicvoid SetPassword(string path,string UserName){


// within this method is initiate with default value(path username and password)

DirectoryEntry oDE = GetDirectoryEntry();

DirectoryEntries users = oDE.Children;

DirectoryEntry edituser = users.Find("CN="+ UserName, "user");

object[] NewPassword =newobject[] { password };

//Error this statement

object ret = edituser.Invoke("SetPassword", NewPassword);


edituser.CommitChanges();

edituser.Close();

edituser.Dispose();

oDE.Dispose();}

Once program executed above yellow highlight. The error was given that “exception has been thrown by the target of an invocation”.

I don’t sure whether “Invoke("SetPassword", NewPassword);” is valid for active directory on window servger 2012 r2 Or Not.

If invalid , we will need to change code another way. For example we will use either  SetPassword  or ChangePassword in System.DirectoryServices.AccountManagement(.NET framework 3.5) instead

In addition I refer new command from Microsoft TechNet(https://technet.microsoft.com/en-us/library/cc782255%28v=ws.10%29.aspx ) for using  reset password.Is it possible to change from "SetPassword"to"NewPassword"?  

I also mention link that is referred vastly for active directory programming with C#http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#46.  This code look like my code.

Please advise me to right solution for fixing this error.











Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>