How to remove eventreceiver when handling AppUninstalling in a RER without getting access denied

I am trying to remove an eventreceiver from the clientContext.Web.EventReceivers
by using DeleteObject() but I am getting Access Denied exception
In my appmanifest.xml I already granted full control to the app
Within my AppEventReceiver I have:
if (properties.EventType == SPRemoteEventType.AppUninstalling)
                SharePointContextToken contextToken = TokenHelper.ReadAndValidateContextToken(properties.ContextToken, OperationContext.Current.IncomingMessageHeaders.To.Host);
                string appOnlyAccessToken = TokenHelper.GetAppOnlyAccessToken(contextToken.TargetPrincipalName, properties.AppEventProperties.HostWebFullUrl.Authority, contextToken.Realm).AccessToken;
                //string appOnlyAccessToken = TokenHelper.GetAppOnlyAccessToken(SHAREPOINT_PID, properties.AppEventProperties.HostWebFullUrl.Authority, TokenHelper.GetRealmFromTargetUrl(properties.AppEventProperties.HostWebFullUrl)).AccessToken;
                using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(properties.AppEventProperties.HostWebFullUrl.ToString(), appOnlyAccessToken))
                    try
                        clientContext.Load(clientContext.Web);
                        clientContext.Load(clientContext.Web.EventReceivers);
                        clientContext.Load(clientContext.Web, web => web.Title);
                        clientContext.Load(clientContext.Web, web => web.CurrentUser.LoginName);
                        clientContext.ExecuteQuery();
                        //IEnumerable<EventReceiverDefinition> receivers = clientContext.LoadQuery(clientContext.Web.EventReceivers.Where(e => e.ReceiverName == "GroupUserAddedRER"));
                        //clientContext.ExecuteQuery();
                        EventReceiverDefinitionCollection receivers = clientContext.Web.EventReceivers;
                        List<EventReceiverDefinition> receiversToDelete = new List<EventReceiverDefinition>();
                        foreach (var rec in receivers)
                            if (rec.ReceiverName == "GroupUserAddedRER")
                                receiversToDelete.Add(rec);
                        foreach (var recToDelete in receiversToDelete)
                            recToDelete.DeleteObject();
                        clientContext.ExecuteQuery();
                    catch (Exception)
                        result.Status = SPRemoteEventServiceStatus.CancelNoError;

Hi,
Check you manifest.xml
You must have the property AllowAppOnlyPolicy
to "true" like below, to use the "GetAppOnlyAccessToken" method
<AppPermissionRequestsAllowAppOnlyPolicy="true">
         Rights of your app...
</AppPermissionRequests>

Similar Messages

  • When I download itunes, it says that Ipod Service failed to start. I checked the services under task manager and when I try to start it, it says access denied. How to I get access and for the ipod service to start and run?

    Please help. My ipod classic could not be recognised by itunes when I connect my ipod to PC. Previously it has been recognised before I updated. This was a while ago now and so I removed all apple files and re installed the latest itunes but am having the same problem.
    When I download itunes, it says that Ipod Service failed to start. I checked the services under task manager and when I try to start it, it says access denied. How to I get access and for the ipod service to start and run?

    Some anti-virus programs (e.g., McAfee) have this rule that can be invoked under the "maximum protection" settings: PREVENT PROGRAMS REGISTERING AS A SERVICE. If that rule is set to BLOCK, then any attempt to install or upgrade iTunes will fail with an "iPod service failed to start" message.
    If you are getting this problem with iTunes, check to see if your anti-virus has this setting and unset it, at least for as long as the iTunes install requires. Exactly how to find the rule and turn it on and off will vary, depending upon your anti-malware software. However, if your anti-virus or anti-malware software produces a log of its activities, examining the log may help you find the problem.
    For example, here's the log entry for McAfee:
    9/23/2009 3:18:45 PM Blocked by Access Protection rule NT AUTHORITY\SYSTEM C:\WINDOWS\system32\services.exe \REGISTRY\MACHINE\SYSTEM\ControlSet001\Services\iPod Service Common Maximum Protection:Prevent programs registering as a service Action blocked : Create
    Note that the log says "Common Maximum Protection: Prevent programs registering as a service". The "Common Maximum Protection" is the location of the rule, "Prevent programs registering as a service" is the rule. I used that information to track down the location in the McAfee VirusScan Console where I could turn the rule off.
    After I made the change, iTunes installed without complaint.

  • [svn] 4706: When handling the damageEvent make sure _contents gets updated with the potentially modified contents of the textFlow .

    Revision: 4706
    Author: [email protected]
    Date: 2009-01-28 07:58:30 -0800 (Wed, 28 Jan 2009)
    Log Message:
    When handling the damageEvent make sure _contents gets updated with the potentially modified contents of the textFlow. Either the contents or the style of the text flow, or both could have triggered the damage event.
    QE Notes:
    Doc Notes:
    Bugs: SDK-18749
    Reviewers: Gordon
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-18749
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/graphics/TextGraphic.as

    Remember that Arch Arm is a different distribution, but we try to bend the rules and provide limited support for them.  This may or may not be unique to Arch Arm, so you might try asking on their forums as well.

  • Get "Access Denied" when click open a PDF file

    Hi Friends,
    Get "Access Denied" when click open a PDF file linked from SharePoint 2013 page.
    What are the route causes any one is remove the permissions are stopped the inheritance permissions of the library.
    Can anyone face the same issue please help me.
    Thanks,
    Tiru
    tirupal

    Hi,
    If you are able to open the same document earlier,then  anonymous access enabled on your doc library then.
    If you are facing this problem in first time,then you do not have required permission (may be custom permission level has been set ) on it.
    Murugesa Pandian.,MCTS|App.Development|Configure

  • Oracle Apex export application getting access denied when trying to download

    DB: 11.2.0.3
    Apex: 4.2.2.00.11
    Apex Listener: 2.0.3.221.10.13
    WLS: 10.3.6.0
    Chrome: Version 29.0.1547.76 m
    and IE 10.0.9200.16660
    I'm the admin of the workspace that has one application. Made a change to the application and went to export the application so I can source control it.
    Followed the Export wizard while in the application, hit the Export/Import button and clicked Export. Changed the File Format to "Database", Export Supporting Object Definitions to "No" and left everything else as default. Clicked the Export Application button and get "Application 108 exported" success maessage. Navigate to the Manage Export Repository and I see the exported application labled "f108.sql and I click on it and I get "Access Denied".
    Whats the trick? What am I missing?
    If I change File Format to "Unix" or "DOS" the file automatically downloads.
    Thx,
    Russ

    Hmm I wonder if it has something to do with:
    bug #16760897
    http://www.oracle.com/technetwork/developer-tools/apex/application-express/apex-422-known-issues-1940409.html
    The bug description mentions ORA-06502, but get_file has a when others exception handler that simply returns "Access Denied".
    What do you folks think?

  • Why am I suddenly getting "Access Denied" when I try to enter text on a form? Windows 7, Reader XI

    I have been using Adobe Reader for many years and scan forms into my computer so that I can fill them with text. I have suddenly started getting Access Denied pop up when I attempt to do this. Does anyone have any thoughts as to why or how to correct?

    Yes, I am adding comments onto a scanned image and the reader is v. 11.0.10. 
    I am Secretary of an organization and rather than hand write all the necessary forms I have them scanned in and then I would position the cursor to type the information on the them. Linda

  • I get access denied when I try to search on your site.

    Please help me. I get access denied when I try to search on your site. I have emptied cache. I tried Safe Mode the way you suggested. Still access denied (though my printer then would not respond to me and I spent $85 to have my It consultant fix that problem.

    Hi,
    You've opened 3 different threads for the same issue. Please only open '''ONE''' thread per support request.
    Continue here [https://support.mozilla.org/en-US/questions/995124?esab=a&s=&r=3&as=s /questions/995124]
    Closing thread

  • I get access denied when I add a page to a workset in EP 7

    I get access denied when I add a page to a workset in EP 7.
    Please advice.

    Hello,
    This seems to be a permission issue. Assign the user id proper permission, say system_admin_role and then try.
    Regards
    Deb

  • How to remove ^M when open with vi

    Hi All,
    O.S is SUN 5.10
    below is .sh file which i need to run but when i opened it with vi it shows ^M, so how to remove this , please suggest.
    ORACLE_SID=test^M
    . oraenv^M
    ^M
    sqlplus /nolog << EOF^M
    conn / as sysdba^M
    ^M
    set echo on^M
    set heading off^M
    set timing on^M
    set serveroutput on^M
    set timing on^M
    ^M
    spool FUL_.SQL.OUT^M
    ^M
    ALTER SESSION ENABLE RESUMABLE;^M
    ALTER SESSION SET RESUMABLE_TIMEOUT = 10800;^M
    alter session set current_schema=partd;^M
    ^M
    @FUL_.SQL^M
    ALTER SESSION DISABLE RESUMABLE;^M
    spool off^M
    EOF^M

    [email protected] wrote:
    Hi All,
    O.S is SUN 5.10
    below is .sh file which i need to run but when i opened it with vi it shows ^M, so how to remove this , please suggest.
    ORACLE_SID=test^M
    . oraenv^M
    ^M
    sqlplus /nolog << EOF^M
    conn / as sysdba^M
    ^M
    set echo on^M
    set heading off^M
    set timing on^M
    set serveroutput on^M
    set timing on^M
    ^M
    spool FUL_.SQL.OUT^M
    ^M
    ALTER SESSION ENABLE RESUMABLE;^M
    ALTER SESSION SET RESUMABLE_TIMEOUT = 10800;^M
    alter session set current_schema=partd;^M
    ^M
    @FUL_.SQL^M
    ALTER SESSION DISABLE RESUMABLE;^M
    spool off^M
    EOF^MWell, this isn't an oracle question ... but ...
    What you are seeing is the result of moving a text file from a dos (windows) platform to a nix platform without proper translation.  In dos, two characters are used to indicate end-of-line.  they are the control characters for Carraige Return and Line Feed (x'13' and x'10').  In nix, only one character. I can't remember if it is the x'13' or the x'10'. Normally, when a file is copied from one platform to another, the copy utility will recognize this and make the proper modification to the file. However, if you ftp the file in binary mode, no translation occurs. Of course, you can ftp in text (ascii) mode only if it is a text file to begin with, so you can't do this with a zip file.
    As already given, there are ways to use vi substitution commands to fix it after the fact. You can also use the utility 'dos2unix' to fix the file after it has landed on the *nix platform. (the actual name of the file may be a variant on the theme of 'dos2unix'.  You may have to google a bit to find it on your OS).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to remove password for the recovery mode wizard which you get by pressing command   r while booting mac with mac os 10.10?

    I've set that password long ago and now forgot on how to remove it.
    Should I go to Apple store for this?

    It's possible you set a firmware password, see if the password dialog is similar to the one on this site…
    http://osxdaily.com/2014/01/06/set-firmware-password-mac/
    Those passwords prevent ALL startup key combinations. Confirm it also happens when you boot holding T (target disk mode - How to use and troubleshoot FireWire target disk mode - Apple Support) If that goes to the password dialog you have a firmware password set.
    Apple suggest you take it to an Apple store to get it reset, you can't remove the battery or remove RAM to reset this, so only Apple should reset it.

  • Windows 2008 R2 intermittently getting access denied when logging in

    Hi, 
    I recently built 2 new Virtual Machines. They both run on Hyper-V (version 6.2x).
    One is Windows 2008 R2 standard and the other Windows 2008 R2 Datacenter. These are both remote desktop servers. 
    These are both connected to a domain. 
    The domain controller is linux/samba based, this will mimic the Windows NT4 style domain controller environment. 
    Within each Virtual Machine I have a remote desktop users group, that is a staff group. 
    Intermittently users get an access denied error when logging on. This only happens when logging on as domain users. 
    If this happened all the time, I might think the machine needed to be removed and re-added to the domain but as it's intermittent, I don't see the trust relationship as the problem. 
    Any ideas? 
    Thanks

    Hi,
    Thanks for your post in Windows Server Forum.
    Before providing you some information, I would like to get some more information to resolve your issue.
    - Have you notice any specific error when trying to remote login?
    - Did you check GPO setting option “Allow log on through Remote Desktop Services”
    As group policy and the user group are interrelated with each other. There are 2 types of user rights.
    (1)   Logon rights  (2) Privileges
    These two plays an important part in allowing an RDP session to the server. Also need to check in GPO Setting for more option.
    a. Allow log on through Remote Desktop Services : Users\Group must be added for Remote Session
    b. Deny log on through Remote Desktop Services : Users\Group must not be added for Remote Session
    For checking the setting in GPO follow below path:
    - Start > Run >gpedit.msc
    - Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment
    For more information, refer beneath article.
    “Allow Logon through Terminal Services (Remote Desktop Services)” group policy and “Remote Desktop Users” group.
    http://blogs.technet.com/b/askperf/archive/2011/09/09/allow-logon-through-terminal-services-group-policy-and-remote-desktop-users-group.aspx
    Hope This Helps!
    Thanks.

  • Getting Access Denied error when try to deploy metro app from VS 11 Beta

    Hi,
    When I try to deploy metro style app from VS11 Beta, i'm getting following error.
    Error : DEP0740 : Access denied. This may be because the application state is locked. A possible cause is "RuntimeBroker.exe" retaining a lock on the storage data for your application. The workarounds are (1) Wait for the "RuntimeBroker.exe" to quit. This
    may take up to 6 minutes. (2) Kill the "RuntimeBroker.exe" process and redeploy. (Note that option (2) may cause loss of data.) 
    Error 2 Opening file from location: F:\...bin\Debug\AppX\AppxManifest.xml failed with error code: 0x80070005. Access is denied.
    Any idea, why?
    CAT

    Hi
    I am facing same problem.Even i have copied project in My Document folder but no luck.
    varsf =
    awaitPackage.Current.InstalledLocation.GetFileAsync(@"ContactXML.xml");
    XmlDocumentxmlDoc;
    using(varstream
    = awaitsf.OpenAsync(FileAccessMode.ReadWrite)).
    Access denied issue.

  • How to remove sound when a take a picture

    i want to remove de sound of my phone when a take a picture

    It's not legal to shut off the shutter sound in many countries. If it still makes the sound with the mute switch on, then it can't be disabled on your phone.

  • How to remove sites when right-clicking Safari in the Dock?

    Right clicking Safari in the Dock shows 3 sites visited awhile ago. There is a diamond shape before each. And each is repeated several times, 16 for one. I've cleared History, closed Safari, removed it from the Dock, restarted Safari. they're still there. Opening them and deleting just increases the amount.
    I'm stymied.
    Any help would be appreciated.

    I've resolved the issue myself.
    First, let me clarify, each of these "sites" had several tabs.
    Here's what worked: by Option-clicking on one closes all other tabs. Of course this can be done manually, closing each tab separately.
    Once all but one tab is showing click the "close", red circle, button and the site deletes from the Safari list in the Dock.
    Not sure why this anomaly happened but I know how to fix it if it should happen again.
    Tricia

  • How to remove customization when fail to entry customization region.

    I make a customization to a region, but this customization make the page fail, that the page can't show the region.
    Then, how can I remove the customization for the region.
    Thanks.

    Sumury,
    1) Profile Option : Personalize Self-service Defn
    Value : Set to "NO"
    This will disable all the personalizations in the application done.
    2) begin
    jdr_utils.deleteDocument('/oracle/apps/apps...../site/0/...PG');
    end;
    Note - Don't forget to commit.
    Regards,
    Gyan

Maybe you are looking for

  • TS3147 HP Officejet Pro K850 print failure

    I bought this printer as it offers a good range of control over print output, since upgrading to Mountain Lion, trying to access these controls from within the print dialogue box instantly crashes whichever program I'm in (MS, Adobe etc). I have down

  • IPhoto allowed me to add location to photos taken by camera with no GPS.  Photos doesn't have this facility. is there any way to do this?

    iPhoto allowed me to add location to photos taken by camera with no GPS.  Photos doesn't have this facility. Is there any way to do this?

  • Trouble installing adobe reader

    I'm attempting to install a copy of adobe reader 9.3, which i downloaded from the adobe website, on a computer running windows xp with service pack three installed, but it fails and gives me an error, which says: "AdbeRdr930_en_US.exe has encountered

  • How to enable php

    I am trying to enable php on my macbook with Lion 10.7.  I have found and changed the http.conf file, but I can't save the changes.  My computer tells me I don't have permission, but it doesn't give me any pop up to confirm my permission.  Can anyone

  • Sizing Tool - Disks

    The sizing tool for SCOM 2012 states the following for a 500 Windows Computers and 100 Network Devices scenario: Role:  Operations Database Server, Operations Data Warehouse Server, Web Console Server & SQL Server Reporting Services Server Hardware: