How to use asp.net login control
Hey all,
I was able to successfully programmatically create a user by using the 'CreateUserWizard' and was able to assign the new user to a specific role. I am now trying to figure out how to use a asp.net login control with Sitefinity 4.
<
asp:Login
ID
=
"Login"
OnLoginError
=
"Login_LoginError"
OnLoggingIn
=
"Login_LoggingIn"
OnAuthenticate
=
"Login_Authenticate"
DestinationPageUrl
=
"/"
runat
=
"server"
>
<
LayoutTemplate
>
<
table
style
=
"margin-top:0px;"
>
<
tr
>
<
td
align
=
"right"
style
=
"padding-right:10px;"
>User Name:</
td
>
<
td
>
<
asp:TextBox
ID
=
"UserName"
MaxLength
=
"256"
Width
=
"185"
runat
=
"server"
/>
<
asp:RequiredFieldValidator
ID
=
"UserNameRequiredFieldValidator"
ControlToValidate
=
"UserName"
Display
=
"Dynamic"
Text
=
"* Required"
runat
=
"server"
/>
</
td
>
<
asp:RequiredFieldValidator
ID
=
"UserNameRequired"
ControlToValidate
=
"UserName"
ValidationGroup
=
"Login"
runat
=
"server"
/>
</
tr
>
<
tr
>
<
td
align
=
"right"
style
=
"padding-right:10px;"
>Password:</
td
>
<
td
>
<
asp:TextBox
ID
=
"Password"
MaxLength
=
"128"
Width
=
"185"
TextMode
=
"Password"
runat
=
"server"
/>
<
asp:RequiredFieldValidator
ID
=
"PasswordRequiredFieldValidator"
ControlToValidate
=
"Password"
Display
=
"Dynamic"
Text
=
"* Required"
runat
=
"server"
/>
</
td
>
<
asp:RequiredFieldValidator
ID
=
"PasswordRequired"
ControlToValidate
=
"Password"
ValidationGroup
=
"Login"
runat
=
"server"
/>
</
tr
>
<
tr
>
<
td
> </
td
>
<
td
colspan
=
"2"
>Not a member? <
a
href
=
"/Register"
>Register here</
a
>.</
td
>
</
tr
>
<
tr
>
<
td
> </
td
>
<
td
>Forgot your password? <
a
href
=
"/Password-Recovery"
>Click here</
a
>.</
td
>
</
tr
>
</
table
>
<
table
class
=
"loginPng"
>
<
tr
>
<
td
width
=
"60"
> </
td
>
<
td
colspan
=
"2"
align
=
"center"
><
asp:ImageButton
ID
=
"Submit"
CommandName
=
"Login"
ImageUrl
=
"/CustomTemplates/MyTemplate/App_Themes/Main/Images/Login_btn.png"
runat
=
"server"
/></
td
>
</
tr
>
</
table
>
</
LayoutTemplate
>
</
asp:Login
>
protected
void
Login_LoginError(
object
sender, EventArgs e)
protected
void
Login_LoggingIn(
object
sender, LoginCancelEventArgs e)
protected
void
Login_Authenticate(
object
sender, AuthenticateEventArgs e)
Hi Doug,
Basically, you needn't use it. Sitefinity defines a public LoginControl that you can drag and drop from the widget toolbar in page editor.
To authenticate, you need something like
User sfUser;
var result = SecurityManager.AuthenticateUser(
this
.MembershipProvider,
this
.UserName,
this
.Password,
this
.RememberMeSet,
out
sfUser);
bool
authenticated = result == UserLoggingReason.Success;
I was trying to do this in a custom master I created. What is the sitefinity login control I should use in the mark up of my master page?
Is it something like this: <sf:Login ..... />? Basically, with my custom master page, I want to declare the control instead of dropping on to a page that inherits from my master page.
Hello Doug,
You have to register a tag prefix for Telerik.Sitefinity.Web.UI.PublicControls namespace, Assembly- Telerik.Sitefinity
Greetings,
Ivan Dimitrov
the Telerik team