No API for UserManager.GetCurrentUser?

Posted by Community Admin on 05-Aug-2018 17:29

No API for UserManager.GetCurrentUser?

All Replies

Posted by Community Admin on 29-Apr-2011 00:00

Please add this into the API. Right now, it seems the only way to do this is:

userManager.GetUser(SecurityManager.GetCurrentUserName())

Posted by Community Admin on 02-May-2011 00:00

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

Posted by Community Admin on 02-May-2011 00:00

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.

Posted by Community Admin on 05-May-2011 00:00

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

Posted by Community Admin on 20-May-2011 00:00

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);

Posted by Community Admin on 20-May-2011 00:00

Thanks Lupi. This works perfectly.

Posted by Community Admin on 20-May-2011 00:00

My suggestion was in hopes of something like this:

var user = userManager.GetCurrentUser();
var user = userManager.GetCurrentUser(providerName);

Posted by Community Admin on 24-May-2011 00:00

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

Posted by Community Admin on 18-Oct-2012 00:00

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;
 
                    
                

This thread is closed