O'Reilly logo

Learning ASP.NET 2.0 with AJAX by Dan Hurwitz, Jesse Liberty, Brian MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Logging In

Now that you have your users, you need a way for them to log in. Edit the master page markup file to add some login functionality.

Add another table row to the layout table, listed in Example 10-3. Note that the ContentPlaceHolder control has been moved to within one of the table cells.

Example 10-3. Code snippet from MasterPage.master containing the login controls

<tr>
    <td width="5px">&nbsp;</td>
    <td width="150px" valign="top">
        <asp:LoginStatus ID="LoginStatus1" runat="server" CssClass="Hyperlink" />
        <br />
        <asp:LoginView ID="LoginView1" runat="server" >
            <LoggedInTemplate>
                <span class="WarningRoutine">Welcome</span>
                <asp:LoginName ID="LoginName1" runat="server"
                    CssClass="WarningRoutine"/>
            </LoggedInTemplate>
            <AnonymousTemplate>
                <span class="WarningRoutine">You are not logged in.
                     Please click the login link to log in to this website.</span>
            </AnonymousTemplate>
        </asp:LoginView>
    </td>
    <td width="5px">&nbsp;</td>
    <td width="700px" valign="top" bgcolor="yellow">
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server" >
        </asp:contentplaceholder>
    </td>
</tr>

This code adds a new row to the table on the master page. The first cell is just a spacer. The second cell holds a LoginStatus control and a LoginView control to go with it. Notice that the CssClass properties of both controls have been set, so you can apply styles to them. The LoginView control has text added to it to present appropriate messages to logged-in or anonymous users.

The third cell in the row now holds ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required