I have a Basic Provider Hosted App (which is an on premise hosted app). It has been integrated with SP2013 and hello world Page is working fine. But when I wanted to develop the actual part, I have to use SharePointContextProvider, but the compiler is throwing an error.

The name 'SharePointContextProvider' does not exist in the current context.

Here is my actual code.

    public ActionResult Index()
        User spUser = null;

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

        using (var clientContext = spContext.CreateUserClientContextForSPHost())
            if (clientContext != null)
                spUser = clientContext.Web.CurrentUser;

                clientContext.Load(spUser, user => user.Title);


                ViewBag.UserName = spUser.Title;

        return View();

In View I want to use the User Name. I am using VS 2012 and SP 2013.


Has your method the following attributes? [SharePointContextFilter]

But more important. Are in your MVC application included the SharePoint context file? SharePointContext.cs and TokenHelper.cs

You can find them here: http://code.msdn.microsoft.com/sharepoint/

|improve this answer|||||
  • Sorry, the SharepointContext.cs is not included in the project. Do I need to manually include them?. – Sadanand Mar 15 '14 at 15:05
  • Yes, add both them and than retry. – Domenico Mar 17 '14 at 8:40
  • Is there any reason why SharePointContext.cs & TokenHelper.cs are not getting included in solution. Because I remember when i created first Provider Hosted App before 18 months it use to get added in the solution. – Azam Khan Nov 23 '15 at 11:39

I resolved this problem by installing Window Foundation Identity.

You can download this from here and download only x64 msu.

|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.