ASP.NET 2.0 Unleashed

Using the LoginName Control

The LoginName control displays the current user's registered username. If the current user is not authenticated, the LoginName control renders nothing.

The page in Listing 20.28 contains both a LoginName and LoginStatus control.

Listing 20.28. ShowLoginName.aspx

<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Show LoginName</title> </head> <body> <form runat="server"> <div> <asp:LoginName FormatString="{0} /" Runat="server" /> <asp:LoginStatus Runat="server" /> <hr /> Additional information is available to registered users. Log in to view the additional information. </div> </form> </body> </html>

When you first open the page in Listing 20.28, the LoginName control displays nothing. However, if you login by clicking the Login link, then the LoginName control displays your username (see Figure 20.12).

Figure 20.12. Displaying the current username with the LoginName control.

The LoginName control supports the following property:

  • FormatString Enables you to format the user name when the user name is rendered

Категории