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.
The authentication mode will need to be set to Forms:
<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:
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.