1

I want to build a remote event receiver for our SharePoint online development site collection. So i followed the step mentioned in this link @ https://derekgusoff.wordpress.com/2017/11/08/remote-event-receivers-youre-all-doing-it-wrong/, for developing and debugging the code.

I did the following main taks:-

1- Run ngrok command link >> type the following; ngrok --http-header=rewrite 53938

2- Got this results:- enter image description here

3- Register the App inside the online site collection, and copy the ClientId and ClientSecret:- enter image description here

4- Add the RER to the site collection. Add-PnPEventReceiver -List "12" -Name "TasksRER" -Url http://f803730b.ngrok.io//service1.svc -EventReceiverType ItemAdded -Synchronization Asynchronous

5- Update the web.config, with the generated ClientId and ClientSecret:-

>  <appSettings file="custom.config">
>     <add key="ClientId" value="6bbe48a5-ffe7-49c6-8a64-1e869a6b0c66" />
>     <add key="ClientSecret" value="hDlQABC+tmtBxeYlJbQNgYWGcfP4KeOekKbxgkALfRE=" />  
> </appSettings> </configuration>

6- Run the service.svc using VS 2019.

7- Inside the ItemAdded, i define this test code, to just clientContext.ExecuteQuery():-

    public void ProcessOneWayEvent(SPRemoteEventProperties properties)

            {    
                var prop = properties;  
                var itemId = properties.ItemEventProperties.ListItemId;
                var listTitle = properties.ItemEventProperties.ListTitle;
                using (ClientContext clientContext = Helpers.GetAppOnlyContext(properties.ItemEventProperties.WebUrl))
                {
                    var list = clientContext.Site.RootWeb.Lists.GetByTitle("12");
                    var item = list.GetItemById(properties.ItemEventProperties.ListItemId);
                    item.Update();
                    clientContext.Load(item);
                    clientContext.ExecuteQuery();

                }
            }

8- but on the clientContext.ExecuteQuery(), i got this exception:-

Microsoft.SharePoint.Client.ServerUnauthorizedAccessException Access denied. You do not have permission to perform this action or access this resource.

Here is a screen shot from VS:- enter image description here

So can anyone advice on this?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.