How to create a username and password login page in Visual Studio

Home > Search > How-to
  by

When creating a new project in Visual Studio, if you select New Project > ASP.NET Web Application > Empty, the project will not automatically include a login system. On the other hand, if you select File > New > Web Site, the website will automatically include a login system. This tutorial is meant to explain how to create a login system when buidling an ASP.NET Empty Web Application.

Follow these steps to create a username and password login page in Visual Studio.

  1. Press Ctrl + Shift + A (or right-click on the name of your new project and select Add > Add New Item).
  2. In the Add New Item dialog box, select Web Form, change the name to signin.aspx, and select Add.
  3. From Toolbox, expand Login, and drag a Login control onto the page

 

The authentication mode will need to be set to Forms:

  1. In Solution Explorer, select the Web.config file
  2. Ensure the system.web markup includes the following:
  <system.web>
   <authentication mode="Forms" />
  </system.web>

 

Press Ctrl F5 to preview the page in a browser. Enter a username and password and attempt to sign in.

A variety of errors may appear:

Because you have not yet created a username and password, error Your login attempt was not successful will appear. Behind the scene's, the SQL Server tables used with the login system should have automatically been created. In Visual Studio, in Server Explorer, expand the database being used, and the newly created tables will be listed.

Follow these steps to create a page that allows a visitor to create their username and password:

  1. Press Ctrl + Shift + A (or right-click on the name of your new project and select Add > Add New Item).
  2. In the Add New Item dialog box, select Web Form, change the name to signup.aspx, and select Add.
  3. From Toolbox, expand Login, and drag a CreateUserWizard control onto the page

Press Ctrl F5 to preview the page in a browser. Register a username and password. Viewing the records of the aspnet_Users table will show the newly created user account.

Return to the signin.aspx page, and attempt to sign in.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments