How to: Add a LoginStatus Button to an ASP.NET Web Page

The LoginStatus control displays the logged-in status of a user, changing based on whether a user is logged in. If your Web site uses ASP.NET membership (forms authentication) for user authentication, you can use the LoginStatus control to display the status of the user. If a user is not authenticated (logged in), the control displays a hyperlink that directs the user to the application's login page. If the user is authenticated, the LoginStatus control displays a hyperlink that users can click to log out of the application. The control can be found under Login in the Toolbox in Visual Studio.

Note

By default, ASP.NET membership and forms authentication is configured to work with a page named Login.aspx. You can change the default login page name in the application's configuration file by setting the loginUrl attribute of the <forms> element.

By default, the LoginStatus control renders a hyperlink. You can configure the hyperlink text by setting the LoginText property. Alternatively, you can configure the LoginStatus control to display an image (an ImageButton control).

By default, ASP.NET provides a site mater page template that includes a LoginStatus control. The control is one of several login controls that are provided in ASP.NET as Web site project templates that provide basic login functionality. For more information, see Walkthrough: Creating an ASP.NET Web Site with Basic User Login. However, if you create custom login pages for your Web site, you will need to add the login controls by hand. For more information, see Walkthrough: Creating a Web Site with Membership and User Login.

  1. Add a LoginStatus control to your page.

  2. Customize the text displayed in the hyperlink by setting the LoginText and LogoutText properties.

To add a login or logout images

  1. Add a LoginStatus control to your page.

  2. Set the LoginImageUrl and LogoutImageUrl to the URL of the image to display as login and logout images.

  3. Optionally customize the alt text displayed for the image by setting the LoginText and LogoutText properties.

See Also

Reference

ASP.NET Login Controls Overview