SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use a provider hosted Apps, so need to work with an App Web and Lists.

Could anybody provide a code snippet to get ClientContext() of the App?

Can I do something like this?

Uri appWeb = new Uri(HttpContext.Current.Request.QueryString["SPAppWebUrl"]);
using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(appWeb, HttpContext.Current.Request.LogonUserIdentity))
share|improve this question
Have you seen this blog… – Robert Lindgren Apr 17 '13 at 14:08
@RobertLindgren, Thanks a lot! It's a very helpful site for me! – Warlock Apr 17 '13 at 14:10
Seemed to be! Good luck! – Robert Lindgren Apr 17 '13 at 14:11
@Warlock if you found a solution you should answer your own question. – Gabriel Smoljár Feb 21 '15 at 12:26

To get clientcontext for app web, you can check the code snippet below:

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

using (var clientContext = spContext.CreateUserClientContextForSPAppWeb())
    Web web = clientContext.Web;

    ListCollection lists = web.Lists;

share|improve this answer

You can get the context of host web and app web to use SharePoint lists and libraries from your tenant and app as well. Contexttoken is mostly used in low-trust provider hosted app. In low-trust provider hosted app, you have to use Azure to host your web application. Azure is providing SPAppToken in url, by getting that you can get authentication token for app. SPHostUrl and SPAppWebUrl are also provided in url. You can get that from url and use that urls to get context.

Here you can get some reference about basic SharePoint Provider hosted app.

Some Links for reference

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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