SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I see all kinds of code to get current SharePoint 2010 logged in user. (I guess current context user from the browser client).

What is the best code? (not currently logged into machine user)

share|improve this question
What is it that you are trying to do and from where? For example, the code for a web part is radically different from a powershell script which is also different from what you would use in a timer job – Dave Wise Apr 19 '12 at 16:19
up vote 0 down vote accepted

Use SPContext.Current.Web.CurrentUser will give you the current user SPUser object (browser). To get the current user loginname use SPContext.Current.Web.CurrentUser.LoginName .

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.