More in this section

Forums / Developing with Sitefinity / How to Login automatically in Sitefinity through API

How to Login automatically in Sitefinity through API

3 posts, 0 answered
  1. Mike
    Mike avatar
    11 posts
    03 May 2012
    05 Sep 2012
    Link to this post

    Our site has a custom registration page, which works fine, and redirects users to a thank you page.

    We need this to automatically log users in. 

    Here's the registration code:
    private void CreateAndRedirect(bool isValidatedMember)
        var result = this.CreateUser(
            this.Mail.Checked ? "1" : "0",
        if (result == MembershipCreateStatus.Success)
            if (isValidatedMember)

    Please can you suggest how we can do this?


  2. Mark
    Mark avatar
    147 posts
    01 Jun 2010
    05 Sep 2012
    Link to this post
    The following is working for me:

    var validate = SecurityManager.AuthenticateUser("Default", Username.Text, Password.Text, true);
    bool authenticated = (validate == UserLoggingReason.Success);

    I noticed you weren't setting a nickname when creating the user. You might want to do that, it's caught up with me before.
  3. David
    David avatar
    38 posts
    05 Apr 2012
    07 Sep 2012
    Link to this post
    Hi Mark

    I am another developer on the project with Andy. 

    We are setting the nickname inside the CreateUser function.

    When we use the SecurityManager.AuthenticateUser the result comes back as 'Success' but when we redirect to another page via Response.Redirect, the successful authentication seems to have been lost.

    Some pseudo code to out line what we are seeing:
    1.var userManager = UserManager.GetManager();
    2.SecurityManager.AuthenticateUser(userManager.Provider.Name, Email.Text, Password.Text, true, out user);
    3.//Request.IsAuthenticated is true here
    6.//Welcome page
    7.//Response.Redirect = false;

    The simplest case I have is a brand new Sitefinity site with one page that has a Login/Logout widget on it. 
    I have a seperate aspx page with a button and a label. Button click calls lines 1 and 2 above and displays the result (which is success).
    Navigate to the sitefinity page and see the login/logout widget showing 'Log in' when I was expecting it to show 'log out'.

    The site is Sitefinity 5.1 using Claims based authentication.

    Any suggestions?

    David Bigg
3 posts, 0 answered