Not able to run Provider Hosted App in SharePoint 2016 On Premise

Brass Contributor

Hi ,

I have created a provider hosted app which I have hosted on Azure. In this app, I am asking for Full Control permission. This provider hosted app contains Client Id & Secret also.
I have created a web job in Azure which is working fine with this provider hosted app in SharePoint Online.
But After installation of the app in On Premise SharePoint 2016, It is not working. I have trusted the app, added Client Id and Client Secret as well and the app gets installed. But when I am running the app it is redirecting me to the app's default page.
Here is the code which I have written on page load event:

        protected void Page_Load(object sender, EventArgs e)
            //function callback to render chrome after SP.UI.Controls.js loads
            function renderSPChrome() {
                //Set the chrome options for launching Help, Account, and Contact pages
                var options = {
                    'appTitle': document.title,
                    'onCssLoaded': 'chromeLoaded()'

                //Load the Chrome Control in the divSPChrome element of the page
                var chromeNavigation = new SP.UI.Controls.Navigation('divSPChrome', options);

            //register script in page
            Page.ClientScript.RegisterClientScriptBlock(typeof(Default), "BasePageScript", script, true);
                var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request);
                Helper.WriteException("contextTokenString: " + contextToken);
                HttpCookie contextCookie = new HttpCookie("contextTokenString");
                // Set the cookie value.
                // Set the cookie expiration date.
                contextCookie.Value = contextToken;
                // Add the cookie.
                HttpCookie hostUrlCookie = new HttpCookie("hostUrlCookie");
                // Set the cookie value.
                // Set the cookie expiration date.
                hostUrlCookie.Value = Page.Request[SharePointContext.SPHostUrlKey];
                // Add the cookie.

                var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

                using (var clientContext = spContext.CreateAppOnlyClientContextForSPHost())
                    //get the current user to be set for the process
                    Microsoft.SharePoint.Client.Web web = clientContext.Web;
            catch (Exception ex)


Here is the error what I am getting :ErrorInProviderHostedApp.png





0 Replies