An Error Occurred While Processing your request – SharePoint Office 365 with Provider Hosted Application

Sathish Nadarajan
 
Solution Architect
June 30, 2017
 
Rate this article
 
Views
9454

We saw many Exceptions, warnings, step by step procedures to create a SharePoint Provider Hosted Applications in the earlier articles. But, still, there are so many exceptions, facing in the real world. Obviously, those mistakes are the simple steps which we are missing, or doing wrong.

In that scenario, today I was creating a new PHA and faced the strange exception as below.

An Error Occurred while processing your request.

 

clip_image002

 

There are many root causes for this issue. But, today the new thing I have done is, hosting the APP Web in an Azure VM with a Public IP, so that my APP will be loaded from the internet.

So in that case, I verified the Client ID,, Client Secret ID, permissions for the Directory Browsing, Permissions for the APP, everything is fine.

The APP is redirecting to the Default.aspx as well.

Then, the Exception Occurs from the below method.

 protected void Page_PreInit(object sender, EventArgs e)
         {
             Uri redirectUrl;
             switch (SharePointContextProvider.CheckRedirectionStatus(Context, out redirectUrl))
             {
                 case RedirectionStatus.Ok:
                     return;
                 case RedirectionStatus.ShouldRedirect:
                     Response.Redirect(redirectUrl.AbsoluteUri, endResponse: true);
                     break;
                 case RedirectionStatus.CanNotRedirect:
                     Response.Write("An error occurred while processing your request.");
                     Response.End();
                     break;
             }
         }
 

If we debug the CheckRedirectionStatus method, it will be going to the TokenHelper.cs, in which we are not supposed to do any changes.

But, always the method returns to the third switch case. That is, CanNotRedirect.

Hence, I wanted to dig a bit further and just saw the fiddler Logs.

clip_image004

The Exception which I was getting is,

SPAppToken=&SPSiteUrl=https%3A%2F%2Fsppalsmvp.sharepoint.com%2Fsites%2FDeveloperSite&SPSiteTitle=DeveloperSite&SPSiteLogoUrl=&SPSiteLanguage=en-US&SPSiteCulture=en-US&SPRedirectMessage=EndpointAuthorityMatches&SPCorrelationId=a25c009e-d09d-3000-24aa-ad0ecb854080&SPErrorCorrelationId=a25c009e-d09d-3000-24aa-ad0ecb854080&SPErrorInfo=The+endpoint+address+%27https%3A%2F%2Fsppalsmvp.sppalsmvp.xyz%2FOffice365.PHA.Licensing.SampleWeb%2FPages%2FDefault.aspx%3FSPHostUrl%3Dhttps%3A%2F%2Fsppalsmvp.sharepoint.com%2Fsites%2FDeveloperSite%26SPLanguage%3Den-US%26SPClientTag%3D0%26SPProductNumber%3D16.0.6621.1205%27+does+not+match+the+app%27s+endpoint+%27sppalsmvp.xyz%27.

Hence, if we saw the exception, The end points were not matching. This is because, during the APP registration, the Domain which we entered is not the correct one.

1. Go to _Layouts/15/appinv.aspx. Enter the Client ID and do the lookup.

clip_image006

2. Verify, whether the App Domain and the Redirect URL are matching. In my case, it is not matching.

3. The App Domain was given like sppalsmvp.xyz. But the Redirect URL is having a full path of https://sppalsmvp.sppalsmvp.xyz/******

4. So, we need to update this APP. SharePoint does not allow us to update the APP. Rather, we can register a new app by going to appregnew.aspx and get a new Client ID, Client Secret ID.

The new values should be

clip_image008

5. Update our APP with the new IDs and Increment the Version.

6. Upload to the AppCatalog

7. Remove the Current app from the site and add it back from the app catalog.

8. Launch the APP.

9. Hurray!!! It works.

clip_image010

A simple mistake, which took about two hours to identify the root cause and a solution.

 

Happy Coding,

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment