Programmatic login not working in 5.1
I was using a programmatic login in Sitefinity 4. However, after switching to version 5, it doesn't work anymore. Can I please be shown how to change this to get this functioning again? My code is below:
protected
void
Login1_Authenticate(
object
sender, AuthenticateEventArgs e)
Credentials credentials =
new
Credentials();
credentials.UserName = Login1.UserName;
credentials.Password = Login1.Password;
credentials.Persistent = Login1.RememberMeSet;
credentials.MembershipProvider =
"HCDBMembership"
;
UserLoggingReason reason = SecurityManager.AuthenticateUser(credentials);
if
(reason.ToString() ==
"UserAlreadyLoggedIn"
)
SecurityManager.Logout(
"HCDBMembership"
, Login1.UserName, credentials);
reason = SecurityManager.AuthenticateUser(credentials);
if
(reason.ToString() ==
"Success"
)
UserManager usrMngr = UserManager.GetManager(
"HCDBMembership"
);
usrMngr.Provider.SuppressSecurityChecks =
true
;
usrMngr.SaveChanges();
System.Web.Security.FormsAuthentication.SetAuthCookie(Login1.UserName, Login1.RememberMeSet);
e.Authenticated =
true
;
if
(Authenticated !=
null
)
Authenticated(
this
,
new
EventArgs());
else
Hello again,
Is there any solution to this problem?
I'll just say I really don't appreciate having to constantly debug things like this every time we upgrade to another version of Sitefinity.
If you would please inform me of the mystery line of code that apparently makes this work. Thanks.
Hello,
In 5.1 you can authenticate a user by simply calling SecurityManager.AuthenticateUser(); and using one of the available overloads. It automatically creates the cookie.
Kind regards,And as you've probably realized, I already knew that, and it didn't work anyway. We've already submitted a support ticket regarding this issue. Thanks anyway.