Fault exception handling
Hello, 

My application as been throwing an exception " Policy prohibits the request from completing" when aim trying to update a person object. 
How can i handle this exception, could you please help me ?

Here is my code:

public string ModifyPersonName(string Name)
        {
            // This  shows the basic steps to modify a resource.
            using (DefaultClient client = new DefaultClient())
            {
                string filterName = "/Person[AccountName='" + HttpContext.Current.User.Identity.Name.Split('\\')[1].ToString() + "']";
                System.Security.Principal.WindowsImpersonationContext ctx = null;
                ctx = ((System.Security.Principal.WindowsIdentity)HttpContext.Current.User.Identity).Impersonate();

                //set credentials and refresh schema
                client.RefreshSchema();

                // get the person(s) object(s) to modify
                foreach (RmPerson person in client.Enumerate(filterName))
                {
                    // create the object to track changes to the resource
                    RmResourceChanges changes = new RmResourceChanges(person);
                    try
                    {
                        changes.BeginChanges();
                        // change something in the resource
                        person.DisplayName = Name.ToString();
                        // modify the resource on the server
                        client.Put(changes);
                        // the operation succeeded: accept the changes.
                        changes.AcceptChanges();
                        // NOTE: after calling AcceptChanges the RmResourceChanges 
                        // object does not contain any more changes to propagate to
                        // the server.
                    }
                    catch (FaultException<AuthorizationRequiredFault> ex)
                    {
                        // approval required
                        return " Requested Submitted, approval is pending";

                        string jsonResponse = new JavaScriptSerializer().Serialize(ex.Message);
                        string aposUnicode = "\\u0027";
                        return jsonResponse.Replace(aposUnicode, "'"); ;
                    }
                    catch (FaultException<PermissionDeniedFault>)
                    {
                        return "Permissions Denied";
                    }
                    catch (Exception ex)
                    {
                        return ex.Message;
                        // an error occurred, so the resource was not modified; 
                        // rollback the changes.
                        changes.DiscardChanges();
                        //throw;
                    }
                    finally
                    {
                        ctx.Undo();
                    }
                }
                return "Requested Submitted, Auto approved";
            }
        }

Thanks,
Sravani
April 27th, 2015 5:53pm

In the FIM portal search requests and look for the request. See what happened, which policies applied, and who the request ran as. That way you can see if your impersonation worked.
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 9:46pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics