none
Fault exception handling RRS feed

  • Question

  • 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
    Monday, April 27, 2015 9:51 PM

All replies

  • 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.

    David Lundell, Get your copy of FIM Best Practices Volume 1 http://blog.ilmbestpractices.com/2010/08/book-is-here-fim-best-practices-volume.html

    Wednesday, April 29, 2015 1:44 AM