Getting IsBackendUser from custom provider

Posted by Community Admin on 04-Aug-2018 04:55

Getting IsBackendUser from custom provider

All Replies

Posted by Community Admin on 28-Feb-2012 00:00

Am I doing something wrong here to get the IsBackendUser property?  It always returns false despite it being true in the Sitefinity backend.  I'm wondering if it has anything to do w/ using a custom provider.

var user = UserManager.GetManager(providerName).GetUser(userId);
bool isBackend = user.IsBackendUser;

What's strange is if I get an instance of User when I authenticate IsBackendUser is populated properly.

UserManager userManager = UserManager.GetManager("IFTMembershipProvider");
 Telerik.Sitefinity.Security.Model.User userToAuthenticate = null;
UserLoggingReason ulr = SecurityManager.AuthenticateUser(userManager.Provider.Name, rtbEmail.Text, rtbPassword.Text, cbRememberMe.Checked, out userToAuthenticate);

In this code userToAuthenticate has the proper IsBackendUser property.  I'd use this instead but I'd need the users password each time to pull it.

Posted by Community Admin on 28-Feb-2012 00:00

I answered my own question and should be using this

var anotherUser = SecurityManager.GetCurrentUser();

I was thrown because in the dev guide they access users with the UserManager.

Posted by Community Admin on 03-May-2012 00:00

Well, I upgraded to Sitefinity 5.0 SP1 and SecurityManager.GetCurrentUser() is deprecated.  It throws an error related to casting from claims authentication.  Now I'm back to the same problem.  My workaround is below but if I wanted another property like IsLoggedIn, LastLoginDate, or LastActivityDate the workaround won't work.  How do I get these other properties?

I'm only able to do this because backend users are tracked as a role:

RoleManager roleManager = RoleManager.GetManager("AppRoles");
if (roleManager.IsUserInRole(SecurityManager.GetCurrentUserId(), roleManager.GetRole("BackendUsers").Id))
 
    //backend
else
 
   //not backend
 

Posted by Community Admin on 03-May-2012 00:00

Sorry, initial post crashed and ended up with a duplicate post...

Posted by Community Admin on 28-Aug-2012 00:00

Did you ever get an answer to this?

Posted by Community Admin on 28-Aug-2012 00:00

I never solved it with a supported solution.  The essential property I wanted was IsLoggedIn so I could log out a user on my custom log in control.  I ended up doing direct read/writes to the user tables.

This thread is closed