I created a new user and added him to the friends role. Make sure you use a strong password with 7 characters or more containing at least one non-alphanumeric character.
8) In the Default.aspx page I am going to use the LoginView control and the LoginStatus control.There are 2 templates,AnonymousTemplate and LoggedInTemplate. I place a LoginStatus control in the AnonymousTemplate.I place a LoginStatus control and the same LoginNamecontrol I had before in the LoggedInTemplate.
<asp:LoginView runat="server">
<AnonymousTemplate>
you are not logged in .
<br />
<asp:LoginStatus ID="LoginStatus1" runat="server" />
</AnonymousTemplate>
<LoggedInTemplate>
You are logged in, <asp:LoginName ID="LoginName1" runat="server" /><br />
<asp:LoginStatus ID="LoginStatus1" runat="server" />
</LoggedInTemplate>
</asp:LoginView>
9) So far we have the same steps as in the previous steps. Now we will add another web form to the site and name it Login.aspx.
We will not use the Login control.
We will add 2 textboxes, a button and a label on the Login.aspx. The markup looks like this
<form id="form1" runat="server">
<div>
Username<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
Password<asp:TextBox ID="TextBox2"
runat="server" TextMode="Password"></asp:TextBox>
</div>
<p>
<asp:Button ID="Button1" runat="server" Text="Log in" Height="26px"
onclick="Button1_Click" />
</p>
<asp:Label ID="Label1" runat="server" Text="Failed!!!!" Font-Bold="true" Visible="False"></asp:Label>
</form>
10) In the Button1_Click event handler routine type
if (Membership.ValidateUser(TextBox1.Text, TextBox2.Text))
{
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,false);
}
Label1.Visible=true;
I use the ValidateUser() method to verify that the supplied username and password are valid.Then redirect the authenticated user to the originally requested page.
Run your application and try to log in. Try first with the correct username and password. Then try with the wrong username or password.
11) Now we will add a new page to our site.I name it GetRoles.aspx. We will get the roles that already exist and add a new role.
12) We add a bulleted list control, a textbox control,a label control and a button control.The markup for the GetRoles.aspx looks like this.
<form id="form1" runat="server">
<div>
<asp:BulletedList ID="BulletedList1" runat="server">
</asp:BulletedList>
</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Create a new role" />
</p>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
13) We create a simple void method to show the existing roles. We call this method from the Page_Load event handling routine.
The method looks like this
private void ShowRoles()
{
BulletedList1.DataSource = Roles.GetAllRoles();
BulletedList1.DataBind();
}
In the Page_Load event handling routine we just call the method
protected void Page_Load(object sender, EventArgs e)
{