Determining the Current User Context inside Sharepoint

Tuesday, May 4, 2010

What is the best way to determine the current user on a custom developed Web Part for MOSS 2007? I found four solutions so far, but I'm pretty sure there's more:

  1. Use System.Web.HttpContext.Current.User.Identity.Name, like in any ASP.Net web application
  2. Use System.Security.Principal.WindowsIdentity.GetCurrent().Name
  3. Have the Current User Filter send the current user to your web part, and (of course) make your web part a consumer of that value.
  4. SPWeb web = SPControl.GetContextWeb(Context); SPUser currentUser = web.CurrentUser;

Posted by Rahul at 2:55 AM  

0 comments:

Post a Comment

Website Updates