Friday 4 April 2008

Using ASP.NET Log-in Controls with Sitecore Extranet

It is simple to use the log-in controls to sign in to a Sitecore extranet. Having dragged a Login control to the design surface of a layout or sub-layout (ie. web form or user control), go to the control’s properties and click the lightning symbol. Double-click the field to the right of the Authenticate item to attach an event handler to the Authenticate event. In the event handler, set the Authenticated property of the AuthenticateEventArgs parameter equal to the success flag of the Sitecore Login() method.

Your Login control definition will be similar to:

<asp:Login ID="Login1" runat="server"
OnAuthenticate="Login1_Authenticate"></asp:Login>

Your event handler will be similar to:

protected void Login1_Authenticate( object sender,
AuthenticateEventArgs e )
{
e.Authenticated = Sitecore.Context.Domain.Login(
Login1.UserName, Login1.Password).Success;
}

2 comments:

FishOfPrey said...

With Sitecore 6 you need to use
Sitecore.Security.Authentication.AuthenticationManager.Login(domainUser, password, persist)

Neil said...

Thanks for the heads up.