Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
ASP.NET 3.5 includes a set of components known as the authentication or security components. These components can be dropped into ASP.NET pages to configure a website that you want to be authenticated. That is, that you want a user to have to login to, to have access to either the entire website or to various components of the website. For the demonstrations in this chapter, I'll use the security website. I'll build the login form using an existing file called Login.aspx. After I open the file, I'll then click the Design button to look at the page in Design mode.
You will see that this is a very simple ASP.NET page. It does not include the standard header control that I have used in other parts of the website. When the login form is presented, you typically don't want to present the Application menu, for example. So here, I'm only presenting the actual banner graphic at the top of the page. And otherwise, this is a completely blank page. The first step to implementing a security system is to create a login form. That's what I'll do with this page. With the file open, go to the Toolbox panel and pin it into place if it's not already setup that way. Then open the Toolbox panel's Login category. You will see a number of components listed there including the Login, the LoginView, the CreateUserWizard and others.
The first step is to create an object called Login Status. The Login Status object detects whether a user is currently logged in. Drag the Login Status object and place it inside the empty paragraph. You will see that the Login Status object has two views, the Logged Out view which is displayed when the user is logged out and the Logged In view that's displayed when the user is logged in. For the Login page, we are primarily concerned with the Logged Out view, what the user sees when they are logged out.
Set the Views option to Logged Out, the original setting. Then go back to the Login category and locate the Login component and drag and drop that and place it directly on top of the Login Status object. You will see that it drops in above the Login Status. And it creates a data entry form that asks the users for their username and their password. You can select the Auto Format option and choose one of the standard looking fields. I'll choose the Simple look which matches the formatting that I have applied to other components in the website, and I'll click OK. Now press Ctrl+S to save and then run the page selecting Debug > Start Without Debugging. The login form asks for the username and password. I haven't actually created user names and passwords yet, but I can go ahead and type in values. I'll type in my name, David and then a password and click Log In. There's a good bit of activity going on the first time I use the page. I'll explain what's going on in a moment.
But when the Login page is finished processing, I see the message 'Your login attempt was not successful.' Please try again. So that's the beginning of creating the login architecture. Now here's what was going on in the background. The first time you run the Login page, the .NET Framework automatically creates a database. I'll go to the App_Data folder, which is automatically created in all ASP.NET websites that are created in Visual Web Developer. And I'll click the Refresh button at the top of the Solution Explorer panel, and you will see a new file has been created called ASPNETDB.MDF. That's an SQL Server database, which is actually being stored locally with the website. Then I'll go to the Database Explorer panel and show that a data connection has been created that connects to that database.
I will open the database file and open it's tables list and you will see that the database structure has been populated automatically with the number of tables. They are all prefixed with aspnet and then there's an underscore character and then there's the name of the table. I will describe the purpose of many of these tables in a later video. But you've successfully created your login page and you've also successfully created a database to store user names, passwords and other aspects of the authentication system.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99534 Viewers
56 Video lessons · 112757 Viewers
71 Video lessons · 81568 Viewers
131 Video lessons · 39158 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.