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?
Asked
Active
Viewed 1,165 times
1 Answers
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