URGENT: Programmatically Logging User Out of Existing Session (2nd post)
Hi,
I posted this question over a week ago but haven't received a (real) response yet. http://goo.gl/wRqey
We made a login box where people enter their username/pwd and then when they click go we log them in programmatically.
Here is the code we use:
SecurityManager.AuthenticateUser(Membership.Provider.Name, username, password, false);
Ben,
Shot in the dark here, but I was able to use this to log a user off from one browser and in on another...
public
void
userLogIn()
var username =
"userone"
;
var password =
"password"
;
var result = SecurityManager.AuthenticateUser(Membership.Provider.Name, username, password,
false
);
if
(result != UserLoggingReason.Success)
if
(result == UserLoggingReason.UserAlreadyLoggedIn)
Credentials creds =
new
Credentials();
Guid userID =
new
Guid(SecurityManager.CurrentUserId.ToString());
creds.MembershipProvider = Membership.Provider.Name;
creds.UserName = username;
creds.Password = password;
SecurityManager.Logout(creds);
SecurityManager.DeleteAuthCookies();
result = SecurityManager.AuthenticateUser(Membership.Provider.Name, username, password,
false
);
Thanks you sir, exactly what we needed!
Awesome, Tim! I've been waiting a week for that exact answer for Sitefinity. Works like a charm.
The only problem now is if I'm logged into one browser as a user, then in another browser I log
in with your code (or with Sitefinity's Login control), it works perfectly, except if I try to do anything
on the first browser again I get the following error message.
This has nothing to do with your code, Tim, but with SF (was getting the error when doing it via SF before)
Any ideas, Sitefinity or Tim or anyone else who has seen this?
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
|
Ben,
Can you check your web.config and verify the line below?
<
roleManager
enabled
=
"false"
/>
This seems to only work for Administrators. If I try this code with a user that isn't in any role I always end up with 'result' returning 'Success'. Has anyone else experienced this?