I am creating Provider Hosted APP and Deploying in Azure and Consuming in my SharePoint 2013 - On Premise.
When I am using:
var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
var clientContext = spContext.CreateUserClientContextForSPHost()
It's Giving an error: Object reference not set to an instance of an object.
But when I am using:
var contextToken = TokenHelper.GetContextTokenFromRequest(Request);
var hostWeb = Request.QueryString["SPHostUrl"];
var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority)
It's giving an error: The parameter 'token' cannot be a null or empty string
If I commenting all code in .cs file then APP is working fine. Its showing .aspx file data. Also when I deployed to Office 365 account I am able to take Client Context.
So how can I take ClientContext
for on-premise?
I have added below code in web.config:
<appSettings>
<add key="ClientId" value="68150c39-ee2d-4d71-aa5d-12d06c52e29a" />
<add key="ClientSecret" value="C7iwn79rs83sQPeP42iCSO1Oo/9nI6yUbvxJM5j1+G4=" />
</appSettings>
Also in azure I have mentioned my Client ID and Client Secret: