We can easily get the SPUser object of the current logged in user:
SPUser user=SPContext.Current.Web.CurrentUser;
This will give the current logged in user. Now you can get user's email, groupName, Name from various properties like:
user.LoginName, user.Email etc
Cheers!!
5 comments:
its late but thank you, so helpful...
Do you know how to do this in client object model ?
I can't return the current user of an sharepoint 2013 autohosted app .
the code always returns the administrator when i return the current user.
Here is the code i'm using:
ClientContext context = new ClientContext("full url");
context.Load(context.Web.CurrentUser);
context.ExecuteQuery();
User user = context.Web.CurrentUser; //always returns "url/Administrator"
thx :)
Thanks for sharing! This is SharePoint, after all! This is what I was looking for to get the SPUser object.
And, for the Anonymous poster from April 2, 2013, you should use the current context to get the currently logged in user.
If you just need to get the User identity object:
System.Web.HttpContext.Current.User.Identity
You can also get the windows process identity like so:
WindowsIdentity.GetCurrent()
helpful
Post a Comment