Try Now
More in this section

Forums / General Discussions / Trying to get the current logged in Sitefinity user

Trying to get the current logged in Sitefinity user

5 posts, 1 answered
  1. Darren
    Darren avatar
    12 posts
    22 Jul 2012
    01 Oct 2012
    Link to this post

    Hi, can anyone help?

    I’m trying to get the current logged in Sitefinity user, but no matter what I try I am not getting the user. This is for a custom module that executes on BeginRequest:


                  public void Init(HttpApplication context)


                         context.BeginRequest += context_BeginRequest;


                  void context_BeginRequest(object sender, EventArgs e)


                         var context = ((HttpApplication)sender).Context;

                         var user = context.User; // <-- Null

                         var sUser = SecurityManager.GetCurrentUser(); // return anonymous user

                         var cUser = ClaimsManager.GetCurrentIdentity(); // returns anonymous identity


    I am currently logged into Sitefinity as the admin user, but no matter what, each of the users above do not show me as that user. Using the regular returns null, while both the SecurityManager and ClaimsManager return empty anonymous users.

    The site is set to use Claims authentication, what else do I need to do to get the current logged in user?

    Thanks in advance 


  2. Randy Garza
    Randy Garza avatar
    19 posts
    24 Feb 2012
    02 Oct 2012
    Link to this post

    Here is an example function that I use to get the current users identity.  If the current user is logged in it will show there first and last name, otherwise it displays Anonymous User.

    private static string GetCurrentSitefinityUser() {
                var identity = ClaimsManager.GetCurrentIdentity();
                var currentUserGuid = identity.UserId;
                if (currentUserGuid != Guid.Empty) {
                    UserProfileManager profileManager = UserProfileManager.GetManager();
                    UserManager userManager = UserManager.GetManager("Default");
                    User user = userManager.GetUser(currentUserGuid);
                    SitefinityProfile profile = null;
                    if (user != null) {
                        profile = profileManager.GetUserProfile<SitefinityProfile>(user);
                    return profile.FirstName + " " + profile.LastName;
                } else {
                    return "Anonymous User";



  3. Darren
    Darren avatar
    12 posts
    22 Jul 2012
    03 Oct 2012
    Link to this post
    Hi Randy,

    Thanks for the reply but the ClaimsManager is returning an anonymous user no matter what.

    It appears perhaps there might be a bug when calling these methods from an HttpModule?

    or do you know if there’s a different method or global event I should be using to make this work?


  4. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    18 Jul 2012
    08 Oct 2012
    Link to this post
    the problem appears to be related to the application event you're intercepting. BeginRequest is too early in the lifecycle to populate the claims authentication information.

    Try running your code in a later event (Such as PostAcquireRequestState) and see if that allows you to get the user data you need.

    Hope this is helpful!
  5. Charles
    Charles avatar
    36 posts
    18 Apr 2011
    17 Jan in reply to SelAromDotNet
    Link to this post

    Do you have a reference where I can find a list of these events? 

    I tried the one you mentioned in 6.3.5000 and it's never called (or breaked on)

5 posts, 1 answered