Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to get the information about the user actually logged (as SPUser) inside an event receivers.

The following line:

Dim currentUser As SPUser = SPContext.Current.Web.CurrentUser

does not work because Current is set to Nothing (null).

I read around that this is due to the asynchronous nature of event receivers but then, how to get the user information I need?

EDIT: I am using ItemCheckingIn receiver to try block a user to check in a file checked out by another user.

Thank you in advance for any help

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Use the synchronous method in your event receiver, and you should be able to retrieve the current user from the context.

share|improve this answer
    
Thank you for the fast answer. I edited my question to give more details. I am not sure I can use a synchronous event receiver to implement this logic, or yes? –  Drake Sep 7 '10 at 10:27
    
Synchronous is the only way to go if you want to stop an operation, as you are doing. Strange however, as CurrentContext should be available at this stage... –  James Love Sep 7 '10 at 10:51
1  
Have you also tried properties.CurrentUserId? –  James Love Sep 7 '10 at 11:06
    
Yes, it worksm thank you! Do you also know how to get SPUser from a CurrentUserId? –  Drake Sep 7 '10 at 12:19
1  
No worries - SPWeb.Users.GetByID() I believe. –  James Love Sep 7 '10 at 12:21
add comment

Not 100% sure what the behaviour is with async event receivers, but did you have a look at

WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();
share|improve this answer
    
This code return me an exception: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. –  Drake Sep 7 '10 at 12:14
add comment

With 2010, the event property bag contains the OriginatingUserToken ,UserDisplayName , and UserLoginName, which you can use to get the original user.

Check the section 5. Impersonation enhancements here : http://extreme-sharepoint.com/2011/12/27/event-receivers-sharepoint-2010/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.