1

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);

                clientContext.ExecuteQuery();

                ViewBag.UserName = spUser.Title;
            }
        }

        return View();
    }

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

2 Answers 2

5

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/

3
  • Sorry, the SharepointContext.cs is not included in the project. Do I need to manually include them?.
    – Sadanand
    Commented Mar 15, 2014 at 15:05
  • Yes, add both them and than retry.
    – Nico
    Commented Mar 17, 2014 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
    Commented Nov 23, 2015 at 11:39
1

I resolved this problem by installing Window Foundation Identity.

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

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.