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.