No API for UserManager.GetCurrentUser? - Ideas & Feature Requests - Ideas & Feature Requests - Progress Community
 Ideas & Feature Requests

No API for UserManager.GetCurrentUser?

  • No API for UserManager.GetCurrentUser?
  • Please add this into the API. Right now, it seems the only way to do this is:
    userManager.GetUser(SecurityManager.GetCurrentUserName())
  • Hello Basem,

    Why not use the GetCurrentUser() method of SecurityManager?
    SecurityManager.GetCurrentUser();
    //Returns the current user


    Regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • Because this does not cast up from SitefinityPrincipal to a Telerik User model object. I would like to work with the Telerik.Sitefinity.Security.Model.User type since that has all aspects of the logged in member.
  • Hi Basem,

    I see your point now, indeed this is not very conveninent, asyou'll need to get the CurrentUserName or CurrentUserId from SecurityManager  and then pass it to UserManager.GetUser(). I have logged your request in our system and we'll be working on it. Thanks for the constructive feedback, we appreciate it.

    Best wishes,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • You could use the following snippet to get a correct reference to the currently logged User (Telerik.Sitefinity.Security.Model.User) - this takes into account the possibility to have different membership providers:

    var currentIdentity = SecurityManager.GetCurrentUser().Identity as SitefinityIdentity;
    var providerName = currentIdentity.Provider;
    var userId = currentIdentity.Id;
    var user = UserManager.GetManager(providerName).GetUser(userId);
  • Thanks Lupi. This works perfectly.
  • My suggestion was in hopes of something like this:

    var user = userManager.GetCurrentUser();
    var user = userManager.GetCurrentUser(providerName);
  • Hi Basem,

    I guess we can add this as well, or better, provide a FluentAPI.

    Best wishes,
    Georgi
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  • this seems works with multiple providers :)    
     if(Context.User.Identity.IsAuthenticated)

                        if (UserManager.UserExistsInAnyProvider(SecurityManager.CurrentUserId))
                        
                            var user = UserManager.FindUser(SecurityManager.CurrentUserId);
                            tipoUsuario = user.ProviderName;