I have an on-premise SharePoint environment for which I'm developing a provider hosted app using visual studio. The web project is hosted an azure. The app project contains a custom ribbon button that goes to the web project. Here I want to get the context token but when trying the following code the context token remains null:

SharePointContextToken contextToken = TokenHelper.ReadAndValidateContextToken(contextTokenString, Request.Url.Authority);

I have also tried the following but here I get that it is an unsupported token:

TokenHelper.GetAppContextTokenRequestUrl(hostWeb, Server.UrlEncode(Request.Url.ToString()));
SharePointContextToken contextToken = TokenHelper.ReadAndValidateContextToken(contextTokenUrl, Request.Url.Authority);

I figure that i get the unsupported token error is because contextTokenUrl contains an url and not an actual token.

How can I get the context token for a SharePoint 2013 on-premise environment with an app and the web project hosted on Azure?

3 Answers 3


The token is passed to your app from SharePoint when the user clicks on your button. In your case, it is not being passed. The typical cause is that the AppID in your app.manifest is not registered. You many need to hit AppRegNew.aspx to get a new id and update your app.manifest.

(Be aware - Visual Studio will update the app.manifest file when you press F5. You should publish from VS when deploying to production.)

  • The app is registered. I looked it up using appinv.aspx with the id in the appManifest file and it exists. The domain and redirect url are the url where the web project is hosted on Azure. So that can't be the cause.
    – Marijn
    Sep 11, 2013 at 14:23
  • I tried registering the app again with appRegNew.aspx. I updated the appmanifest file and web.config with the new id and secret but the token is still null. I published it from Visual Studio and checked the appmanifest file again if it contained the correct id (which it did) before adding the app to SharePoint.
    – Marijn
    Sep 12, 2013 at 8:23

If you have addressed the obvious issue of client registration by creating a new Client ID and secret, then this leaves the App manifest file. Just an an after though, please also check your web.config again and ensure that the new App ID and secret is there as well.

Are you able to share the manifest file?


Just want to describe how I solved this issue. I registered the app under AppRegNew.aspx and always get app token as null (web hosted in azure). Later I found that while registering your app you need to provide domain without "www", i.e. myapp.azurewebsites.net instead of www.myapp.azurewebsites.net.


  • I am working on provider hosted app, i found same issue of context is null. When i deploy app from visual studio app is working totally fine but when i try to add app in app catalog and then sometime it is giving error of context is null. Please help from last one week I am looking into this issue.
    – Richa Jain
    Jun 12, 2017 at 13:55
  • My access token is not generating itself, after every 12-14 hrs app automatically stops working itself.
    – Richa Jain
    Jun 12, 2017 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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