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;
 Console.WriteLine("current user: " + user.LoginName);

1 Answer 1


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.

  • it does not showing current user. showing previous user name
    – user25864
    May 19, 2014 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, 2014 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, 2014 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, 2014 at 6:00
  • in visual studio for client object model
    – user25864
    May 19, 2014 at 6:01

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.