SharePoint Online RER Configuration and Debugging #2 (ClientContext = NULL)

As for this question, I found the mainly reason is ClientID and ClientSecret. I found sometimes I register a new ClientID and ClientSecret cannot work. So I changed some information format. as follows:

When I register the App, Redirect URI: I give it whole URL ( must include Port Number ) like this   https://XXXXX.azurewebsites.net:443/Pages/SettingSecurity.aspx

before solving the issue, My redirect URI is “https://XXXXX.azurewebsites.net” … I don’t know whether or not this is the mainly problem to influence my code. But finally I sorted it out.

Other Problems are:

AppManifest: When I published the “App for SharePoint”, I didn’t change the Url (~remoteAppUrl ) to the Url of the Production with the port number explicit.

  1. Debugging: <StartPage>~remoteAppUrl/Pages/SettingSecurity.aspx?{StandardTokens}</StartPage>
    Production:   <!–<StartPage>https://XXXXX.azurewebsites.net:443/Pages/SettingSecurity.aspx?{StandardTokens}</StartPage>–>
  2. if you wanna debug it, pay close attention to the following line: ClientId=”*” ( don’t need to add any ClientId, keep * ), on the contrary, if you wanna publish it into the Production, you need to change ” * ” to ID like ( ad95a175-b4bb-481e-b644-526b5f37ae02 )

<AppPrincipal>
<RemoteWebApplication ClientId=”*” />
</AppPrincipal>

Elements.XML: It’s the same with the AppManifest

  1. <UrlAction Url=”~remoteAppUrl/Pages/SettingSecurity.aspx?{StandardTokens}&amp;SPListItemId={ItemId}&amp;SPListId={ListId}&amp;SPSource={Source}&amp;SPListURLDir={ListUrlDir}&amp;SPItemURL={ItemUrl}”/>
  2. <!–<UrlAction Url=”https://XXXXX.azurewebsites.net:443/Pages/SettingSecurity.aspx?{StandardTokens}&amp;SPListItemId={ItemId}&amp;SPListId={ListId}&amp;SPSource={Source}&amp;SPListURLDir={ListUrlDir}&amp;SPItemURL={ItemUrl}”/>–>

 

SharePoint Online RER Configuration and Debugging #1

  • Create Project for Remote Event Receiver

Untitled picture

Step2

  • Need to type “USER ACCOUNT” and “PASSWORD” –> Choose “SharePoint Online” –> “Next”

Step3Step4Step5

  • Change the Properties of the Project (SharePointAddIn1)
    1. Handle Add-in Install –> “True”
    2. Handle Add-in Uninstall –> “True”

Step7

  • When you change the properties ( Handle Add-in Install and Handle Add-in Uninstall ), the VS .NET will add Folder called “Services” and .svc file called “AppEventReceiver.svc” under the services folder automatically. This is for Default Lists or Document Libraries.

Step8

If you wanna create custom List, you need to add Remote Event Receiver on your own for installation ( Because we need some information of the RER ). As below: ( Add Remote Event Receiver )

Step9Step10

Step11Step12

  • Config the AppManifest.xml and Web.Config
    1. <StartPage> … </StartPage> –> Point off the Page of the list or Document Library where the RER will be installed on the SharePoint Online. E.g.
      1. Document Library : Document Library URL
      2. List : List URL
    2. ClientId

Step13

  • Config Permission – AppManifest.xml

Step14

  • Grant Permission to an App: https://spexptw.sharepoint.com/sites/dev/_layouts/15/appinv.aspx
    1. App Id ( the same with the Client Id )
    2. Title: the same with the Title on the (…/_layouts/15/appregnew.aspx)
    3. App Domain: the same with the App Domain on the (…/_layouts/15/appregnew.aspx)
    4. Redirect URI: the same with the Redirect Uri on the (…/_layouts/15/appregnew.aspx)
    5. Permission Request XML ( copy from AppManifest.xml and paste it, then click “OK” ):

<AppPermissionRequests AllowAppOnlyPolicy=”true”>

   <AppPermissionRequest Scope=”http://sharepoint/content/sitecollection&#8221; Right=”FullControl” />

</AppPermissionRequests>

Step15

  • Change Web.Config
    1. ClientId
    2. ClientSecret
  • Add Key ( for debugging )
  • <add key=”RERdebuggingServiceBusUrl” value=”https://?????.servicebus.windows.net/3845660891/3839167270/obj/0c454565-deeb-4a44-b8b6-9cce0ff955e1/Services/AppEventReceiver.svc” />
  • “Key” comes from “string debugEndpoint = System.ServiceModel.OperationContext.Current.Channel.LocalAddress.Uri.ToString(); for Debug

 

 

Step16

  • Config Debug ( Right click on the Project name: SamplePnp ) –> click “Properties”
    1. Microsoft Azure Service Bus connection string ( come from Azure ): Primary Connection String

Step17Step18

  • Open the “AppEventReceiver.svc.cs“, Add some code inside. /// When the event was triggered, the process will JUST get into this program, event though you add Remote Event Receiver for Custom Lists

/// Simple Example: ProcessEvent mean -ing; ProcessOneWayEvent mean -ed

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)

       {

           SPRemoteEventResult result = new SPRemoteEventResult();

 

           switch (properties.EventType)

           {

               case SPRemoteEventType.AppInstalled:

                   HandleAppInstalled(properties);

                   break;

               case SPRemoteEventType.AppUninstalling:

                   HandleAppUninstalling(properties);

                   break;

               case SPRemoteEventType.ItemDeleting:

                   {

                       result.ErrorMessage = “Enhanced Records Manager prevents classes / folders / parts or records being deleted” +

                           “, you must use a disposal to remove them.”;

                       result.Status = SPRemoteEventServiceStatus.CancelWithError;

                       break;

                   }

           }

           return result;

       }

  • Done

{ Question } : If you use the RER for Item deleting

  1. Problem is that when you delete the item all you get is a blank screen when you do it from a list view.
  2. The delete is stopped but no message displayed just a blank screen.
  3. However when you do it from the View Properties page then the delete is stopped and the error message is displayed.

{ Answer } : So now when you install our app it checks for the Minimal Download Strategy ( Site Feature ) and if its activated then deactivates it.

From <https://simpleinnovationassociates.wordpress.com/2015/02/13/display-error-message-from-an-office-365-sharepoint-online-remote-event-receiver/>

Minimal Download Strategy

A technique that delivers a faster and more fluid page navigation experience, in pages and site templates that support it, by downloading and rendering only those portions of a page that are changing.

SharePoint Apps vs Cloud Business Apps

Cloud Business Apps

Create Cloud Business Apps in Visual Studio

By using the Cloud Business App template in Visual Studio, you can quickly and easily create line-of-business apps that are hosted on SharePoint for Office 365 and based on Visual Studio LightSwitch technologies. Users can download and run cloud business apps on desktop computers and most mobile devices.

Understanding LightSwitch

Visual Studio LightSwitch is a development environment designed to simplify and shorten the development of businesses applications and data services. LightSwitch makes it easy to create data-centric business applications that can consume a variety of data sources and create clients that can run on a variety of devices. With LightSwitch you can:

  • Build HTML5-based apps that run on all modern devices
  • Consume and aggregate multiple data sources like databases, SharePoint and OData
  • Eliminate plumbing code and focus on what makes your application unique
  • Have flexible deployment and cloud hosting options including Azure and Office 365
  • Trust that your solution is built on best-of-breed technologies and practices

SharePoint Apps

Create Apps for SharePoint by using Visual Studio

By using Visual Studio, you can create apps for SharePoint, which are solutions that have a small footprint and that use standards-based technologies such as HTML5, JavaScript, and OAuth. You typically design one of these apps to help users complete a specific task or related set of tasks. For example, you can create an app to track travel expenses or maintain a team sign-up sheet.

What you can do in an app for SharePoint > Using SharePoint Components

Almost every major type of SharePoint component can be part of an app for SharePoint, including custom content types, list templates, list instances, pages, workflows, event handlers, and many more. You can also have built-in Web Parts, including a Silverlight Web Part that hosts a Silverlight application and an app part that wraps an IFrame.

refer to, http://sharepoint.stackexchange.com/questions/101661/sharepoint-apps-vs-cloud-business-apps