How to get the current logged in user in Event handler

Recently i faced a problem in event handler to do some operation for the current logged in user,but inside event handler SPContext object is null. So after some probe we found a way to get the current user object .

For this we need to get the HttpContext object inside the constructor of the event handler

Here is the sample code :

———————————————–

HttpContext current;

/// <summary>

/// Constructor to get the current logged in user details

/// </summary>

public ListEventHandler()

{

current = HttpContext.Current;

}

————————————————-

Now to get the login name of the current user use this code:

string currentUserLoginName = current.User.Identity.Name;

————————————–

So your job is done

Enjoy!!!

Advertisement

~ by Saurabh Mittal on September 19, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.