6

I am trying to develop the SharePoint ProviderHosted App. I am generating ClientID and ClientSecret from my O365 environment. And passing both in Web.Config file and AppManifest.xml file.

But when I am trying to run the app the "SPAppToken" in Request.Form not getting the value.
I mean its value is null. I don't know why. And after that I try to run the same app by making it AutoHosted again the same thing happened that Its value null again.

The Code I am using is as Follows:

var contextToken = TokenHelper.GetContextTokenFromRequest(Page.Request);
var hostWeb = Page.Request["SPHostUrl"];

using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority))
{
     clientContext.Load(clientContext.Web, web => web.Title);
     clientContext.ExecuteQuery();
     Response.Write(clientContext.Web.Title);
} 

This code by default created when I create a new App.
Any Help will be Appreciated.!!

| improve this question | | | | |
1

The SPAppToken is part of the form that Sharepoint POSTS to your custom web application. If that is null, SharePoint is not posting it or (more likely) the web application is being requested directly (via GET). The general flow for this scenario is for your app to redirect back to SharePoint so it can start the POST flow from the beginning.

If you're convinced that SharePoint is not POSTing the SPAppToken, verify the method is POST in your debugging. Maybe you have some weird logic that's causing the initial POST to hit and get redirected back to itself or something. Just a thought.

If it's definitely not POSTing the SPAppToken, check the form and see if the SPAppToken is named something different. The name is actually a hard coded string in the TokenHelper that has a few different variants. Maybe you changed this around?

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.