views:

79

answers:

2

How can I know the user logging onto SharePoint through code? I am using WebPart inside it SmartPart and inside it a User control.

+4  A: 

You can get the user informations with :

SPContext.Current.Web.CurrentUser

Here are some informations like email, ID, Groups, Name... Type Ctrl + Space ;)

Hope it helps...

Timothée Martin
Thanks a lot man :) That's exactly what I was looking for.
Ahmad Farid
A: 

I am assuming your SharePoint site is running under Windows Authentication (which most would be). In that case you can get the current user name using:

System.Web.HttpContext context = System.Web.HttpContext.Current;
string username = context.User.Identity.Name;
Jeff Widmer
You can directly access to the SharePoint HttpContext with SPContext :)
Timothée Martin
This also work. Thank you for your support :)
Ahmad Farid