public ActionResult Index() { User spUser = null; var accessTokenInfo = WebAPIHelper.GetAccessTokenInfo(Request); using (var clientContext = accessTokenInfo.CreateUserClientContextForSPHost()) { if (clientContext != null) { spUser = clientContext.Web.CurrentUser; clientContext.Load(spUser, user => user.Title); clientContext.ExecuteQuery(); ViewBag.UserName = spUser.Title; } } HttpCookie cookie = new HttpCookie("CacheKey", accessTokenInfo.CacheKey); Response.SetCookie(cookie); return(View()); }