User Still Logged in Issue
I am trying to authenticate an ldap user and am retrieving the user using the LdapMemberhsipoProvider. The IsLogginedIn flag on the user is set to false, however when I try to authenticate I get UserLoggingReason.UserAlreadyLoggedIn.
LdapMembershipProvider ldapManager = new LdapMembershipProvider();
User user = ldapManager.GetUser(netid);
if (user != null)
if (user.IsApproved && !user.IsLockedOut)
if (user.IsLoggedIn)
Trace.Write("User was logged in, so signing out");
SecurityManager.Logout("LDAP Users", netid);
SecurityManager.DeleteAuthCookies();
validate = SecurityManager.AuthenticateUser("LDAP Users", netid, true, out user);
Hello Peter,
I am attaching a sample with a working example page of the intended behaviour. Generally the only difference to make it work is how you get the user. You need to use Sitefinity's UserManager instead of LdapMembershipProvider and just pass the Provider Name when you get the manager instance.
Here is the code snippet change that is relevant:
UserManager manager = UserManager.GetManager(
"LdapUsers"
);
string
ldapId = UserName.Text;
User user = manager.GetUser(ldapId);
if
(user !=
null
)
if
(user.IsApproved && !user.IsLockedOut)
if
(user.IsLoggedIn)
Trace.Write(
"User was logged in, so signing out"
);
SecurityManager.Logout(
"LdapUsers"
, ldapId);
SecurityManager.DeleteAuthCookies();
var validate = SecurityManager.AuthenticateUser(
"LdapUsers"
, ldapId,
true
,
out
user);
LoginLabel.Text = validate.ToString();
Make sure your membership provider's name is actually "LdapUsers" and you should be good to go.
Let me know if this helps!
That was my issue, thank you