Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

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

To allow users to log in to an ASP.NET application that uses ASP.NET membership (forms authentication) for user authentication, you can use the LoginStatus control. The LoginStatus control detects a user's authentication status. If a user is not authenticated, the control displays a button that directs the user to the application's login page. If the user is authenticated, the LoginStatus control displays a button that users can click to log out of the application.


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 button. You can configure the button text by setting the LoginText property. Alternatively, you can configure the LoginStatus control to display an image (an ImageButton control).

To add a login button to an ASP.NET Web page

  1. Add a LoginStatus control to your page.

  2. Customize the text displayed in the button 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, respectively.

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

See Also

Other Resources

Login ASP.NET Controls

Community Additions

© 2015 Microsoft