Getting IsBackendUser from custom provider
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;
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);
I answered my own question and should be using this
var anotherUser = SecurityManager.GetCurrentUser();
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
Sorry, initial post crashed and ended up with a duplicate post...
Did you ever get an answer to this?
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.