0

If I logged in as a different user in SharePoint below code doesn't show current user logged in user, what is the problem?

Web web = clientContext.Web;
 User user = clientContext.Web.CurrentUser;
 clientContext.Load(web);
 clientContext.Load(user);
 clientContext.ExecuteQuery();
 Console.WriteLine("current user: " + user.LoginName);
0

clientContext.Web.CurrentUser will show the user that credentials was used in clientContext object.

Please check which users credentials you are using in clientcontext object.

| improve this answer | |
  • it does not showing current user. showing previous user name – user25864 May 19 '14 at 5:52
  • Please tell me how are creating client context object. Are you running this page from sharepoint itselt or some other application – Aanchal May 19 '14 at 5:55
  • i have logged in from different user in sharepoint but in code when i checked current user it doesn't show me my current user as logged in user – user25864 May 19 '14 at 5:58
  • Where is your code running that you mentioned? Sharepoint page code behind or some other Application. you can try server object model for this if it is in sharepoint context. this.web.currentuser. – Aanchal May 19 '14 at 6:00
  • in visual studio for client object model – user25864 May 19 '14 at 6:01

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.