Get the current logged on user using the Client Object Model

Posted on 8/27/2010 @ 5:44 AM in #SharePoint by | Feedback | 2383 views

Here is a little script that I know I’ll need later. This script will get you the currently logged on user’s loginID using the client object model. Of course there are many other properties and methods on the object, but I leave it upto you to explore those -

  1:     var context = SP.ClientContext.get_current();
  2: 	var currentUser = context.get_web().get_currentUser();
  3: 	context.load(currentUser);
  4: 	context.executeQueryAsync(
  5: 		function (sender, args) {			
  6: 			alert(currentUser.get_loginName());
  7: 		}
  8: 		, FailureHander);

Sound off but keep it civil:

Older comments..

On 10/15/2010 8:04:56 AM Zia said ..
This is a very good post, I want to ask a question: i have my sharepoint portal running Moss 2007, and on going to search page, i'm loading the search application hosted on sharepoint 2010 box, but when i'm accessing the sharepoint 2010 site, its asking windows authentication popup(asking for username and password), i want to suppress this dialogue box which pops whenever i access the site which is hosted on 2010 box.

plz help.

On 12/5/2011 10:08:41 AM Dennis Karides said ..
Actually, it did not work for me. Could you help me out how to do it? Itis very important in my new project? Could you give me additional details?