03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Introduc<strong>in</strong>g the Log<strong>in</strong> Controls x 617<br />

<br />

<br />

<br />

10. Save all your changes <strong>and</strong> request Log<strong>in</strong>.aspx <strong>in</strong> your browser. Log <strong>in</strong><br />

with the account <strong>and</strong> password you created <strong>in</strong> a previous exercise (you<br />

may need to log out first by click<strong>in</strong>g the Logout l<strong>in</strong>k). If you don’t recall<br />

the username <strong>and</strong> password, simply click the Sign Up l<strong>in</strong>k to create a new FIGURE 16-10<br />

account. Note that as soon as you are logged <strong>in</strong>, the footer displays the text visible <strong>in</strong> Figure 16-10.<br />

11. Click the Log<strong>in</strong> item <strong>in</strong> the Menu or TreeView to go to the Log<strong>in</strong> page. Instead of the Log<strong>in</strong> control<br />

you should now see a message <strong>in</strong>dicat<strong>in</strong>g that you are already logged <strong>in</strong>.<br />

12. Click the Logout l<strong>in</strong>k <strong>in</strong> the footer at the bottom of the page. The page refreshes <strong>and</strong> displays the<br />

Log<strong>in</strong> control aga<strong>in</strong>. Additionally, the text from the footer has now disappeared.<br />

How It Works<br />

You started by add<strong>in</strong>g a Log<strong>in</strong>View to the Log<strong>in</strong> page to wrap the Log<strong>in</strong> control <strong>and</strong> a text message.<br />

The Log<strong>in</strong> control is shown when the user is not logged <strong>in</strong>, whereas the text is displayed for logged-<strong>in</strong><br />

users only.<br />

The code <strong>in</strong> the footer of the master page conta<strong>in</strong>s a Log<strong>in</strong>Name control that displays the name of the<br />

user that is logged <strong>in</strong>. It doesn’t display anyth<strong>in</strong>g for anonymous users. To control the text be<strong>in</strong>g displayed,<br />

you use the FormatStr<strong>in</strong>g property:<br />

<br />

At run time, the {0} is replaced with the user’s name.<br />

By default, the Log<strong>in</strong>Status you added displays a l<strong>in</strong>k to enable users to log <strong>in</strong> <strong>and</strong> log out. Because<br />

the Menu or the TreeView already conta<strong>in</strong>s a l<strong>in</strong>k to the Log<strong>in</strong> page, the footer uses a Log<strong>in</strong>View aga<strong>in</strong><br />

to display the Logout text only when the user is currently logged <strong>in</strong>. If you want to add a Log<strong>in</strong> l<strong>in</strong>k as<br />

well, you can extend the Log<strong>in</strong>View with an anonymous template <strong>and</strong> an additional Log<strong>in</strong>Status or<br />

remove the entire Log<strong>in</strong>View so the Log<strong>in</strong>Status is visible to all users.<br />

In addition to the controls you have seen that enable a user to log <strong>in</strong> <strong>and</strong> that use the current user’s<br />

log-<strong>in</strong> status to show or hide relevant content, the Log<strong>in</strong> category of the Toolbox conta<strong>in</strong>s three<br />

more controls that enable users to sign up for a new account on the site, to change an exist<strong>in</strong>g password,<br />

<strong>and</strong> to recover a lost password. These controls are discussed next.<br />

CreateUserWizard<br />

You briefly saw CreateUserWizard at work <strong>in</strong> an earlier exercise. But the control has a lot more to<br />

offer than the st<strong>and</strong>ard behavior you saw <strong>in</strong> that exercise.<br />

To start with, the control has a long list of Text properties, such as CancelButtonText,<br />

CompleteSuccessText, UserNameLabelText, <strong>and</strong> CreateUserButtonText, that affect the text<br />

used <strong>in</strong> the control. All properties have good (English) defaults, but you can change them if they<br />

don’t suit your needs.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!