+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Programmatic login not working in 5.1

Programmatic login not working in 5.1

4 posts, 0 answered
  1. Ryan Dailey
    Ryan Dailey avatar
    41 posts
    Registered:
    08 Mar 2010
    20 Feb 2013
    Link to this post

    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
            {
            }
        }

  2. Ryan Dailey
    Ryan Dailey avatar
    41 posts
    Registered:
    08 Mar 2010
    04 Mar 2013
    Link to this post

    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.

  3. Atanas Valchev
    Atanas Valchev avatar
    414 posts
    Registered:
    04 Jan 2016
    07 Mar 2013
    Link to this post
    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,
    Atanas Valchev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Ryan Dailey
    Ryan Dailey avatar
    41 posts
    Registered:
    08 Mar 2010
    12 Mar 2013 in reply to Atanas Valchev
    Link to this post
    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.
4 posts, 0 answered