4

What is a way that I can log a user in to secure front end area in Kentico? Should I use the ASP.NET membership API?

rocky
  • 7,506
  • 3
  • 33
  • 48
Ben E G
  • 971
  • 8
  • 16

1 Answers1

6

assuming that you have 2 textboxes and an event handler (txtEmail, txtPassword and btnSubmit_Click ) and that you have setup the appropriate roles in the kentico site manager you can use something like this:

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        CMS.SiteProvider.UserInfo ui = CMS.SiteProvider.UserInfoProvider.AuthenticateUser(txtEmail.Text, txtPassword.Text, CMS.CMSHelper.CMSContext.CurrentSite.SiteName);
        if (ui != null)
        {
            System.Web.Security.FormsAuthentication.SetAuthCookie(ui.UserName, true);
            CMS.CMSHelper.CMSContext.SetCurrentUser(new CMS.CMSHelper.CurrentUserInfo(ui, true));
            CMS.SiteProvider.UserInfoProvider.SetPreferredCultures(ui);
            Response.Redirect("MY_SECURE_PAGE");
        }
        else
        {
            litMessage.Text = "Email/Password incorrect";
        }
    }
Grimboify
  • 218
  • 1
  • 11