24
ASP.NET The Clock Project

ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Embed Size (px)

Citation preview

Page 1: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

ASP.NET

The Clock Project

Page 2: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

The ASP.NET Clock Project

The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn your way around Visual Studio .NET.After launching the development environment for the first time, you will explore its windows and practice using controls that enable you to create, edit, run, and debug an application.Let us work through the clock project together.

Page 3: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Creating an ASP.NET Project

Put Visual Studio .NET on your Windows taskbar to start it up quickly.Create a new project with Visual Studio .NET.Understand what is meant by the term Web Form.

Page 4: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

The Clock Script

Create an ASP.NET page that tells the time.In HTML view, we write the following code:

<h1>The Clock Strikes</h1>The time is <% = DateTime.Now.ToLongTimeString() %>

Page 5: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Running an ASP.NET Project

Use the start button to run a project.Debug a project containing errors.Understand how actions you take in Design View change the code in HTML View.

Page 6: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Using the Toolbox

Open the toolbox and drag controls onto the design surface.Modify properties of controls on the design surface.Discover how the design surface uses absolute positioning to place objects on screen.Illustrate this by creating an Update button.

Page 7: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

ASP.NET Top Secret ProjectPart 6: Goals and Objectives

The Top Secret Project is the topic of Part 6 of Advanced Web Design.It enables you to look further under the hood of ASP.NET.You learn how to create a database with Microsoft Access or SQL Server, populate the database with user names and passwords, and use ADO.NET to decide who can access your site.

Page 8: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectChapter 24: Creating the Database

Chapter 24 gets you started by having you use either Microsoft Access or SQL Server to create the Top Secret database.You make a Users table that will contain the names and passwords of your users.You populate the database with a few users allowed to access your top secret stuff.

Page 9: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectChapter 25: Listing the Users

In Chapter 25, you write an ASP.NET script that reads information from the Top Secret database and displays it in a listbox on a Web page.The design process you follow in this chapter will teach you how to use a code-behind page to separate your programming from the Web page.You will call upon the assistance of the Code Designer to help you create the code-behind page, on which you will write a little program that uses a data adapter to connect to a database.After issuing an SQL query that fills a dataset with the names of your Top Secret users, you will read from the dataset and load into the listbox the name of each user permitted access to the Top Secret database.

Page 10: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectChapter 26: Adding New Users

At the moment, if you want to add a user to the Top Secret database, you need to use your database software (i.e., Microsoft Access or SQL Server) to do so.Suppose you are at a remote location, away from your server, and the need arises to add another user to the database. Wouldn’t it be nice to have a way to add new users remotely?In Chapter 26, you will add to the Users.aspx Web page an Add User button that enables you to add new users remotely over the Web.

Page 11: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectChapter 27: Updating Users

You need to update a database when information changes in a dataset.Suppose one of your Top Secret users gets a new e-mail address, for example.Changing that user’s e-mail address requires you to connect to the database, locate the user’s record, change the e-mail address in the dataset, and update the database.In Chapter 27, you will learn how to make these kinds of changes in a database.

Page 12: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectChapter 28: Deleting Users

In Chapter 28, you will create a Delete button that will enable you to remove users from the database who no longer should have access to your top secret information.When you write the code for the Delete button, you will learn the dataset method for deleting records from a database. This will round out the database functions you have learned in this part of this book.By the time you complete this chapter, you will have learned how to insert, update, retrieve, and delete records from a database.

Page 13: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectChapter 29: Logging Users In

Authentication is the process of determining whether a user should be permitted or denied access to a resource such as a Web site. On the Internet, Web sites that are not publicly accessible require users to log in to gain access.In Chapter 29, you will create a login screen for the Top Secret project. The login screen will contain three controls: a text field into which the user will type a user name, a text field into which the user will type a password, and a login button.When the user presses the login button, a script will gather the name and password from the login form and check to see whether the user should be permitted access. If so, the script will set an authentication cookie that will permit the user to access the Web site. If the name and password are not recognized, on the other hand, the user will be denied access to your top secret stuff.

Page 14: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectChapter 26: Adding New Users

At the moment, if you want to add a user to the Top Secret database, you need to use your database software (i.e., Microsoft Access or SQL Server) to do so.Suppose you are at a remote location, away from your server, and the need arises to add another user to the database. Wouldn’t it be nice to have a way to add new users remotely?In Chapter 26, you will add to the Users.aspx Web page an Add User button that enables you to add new users remotely over the Web.

Page 15: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectAdding a Button

To add a button to an ASP.NET page, follow these steps:

Drag a button from the WebForms toolbox to the design surface.Edit the button’s properties to give it the text and ID you want it to have.Double-click the button to make the code generator create its handler.Write the script to handle the button.

Page 16: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectAdd User Script

The add user script performs the following tasks:

Get the data from the form.See if the user already exists.Add the new user to the data table.Update the database.Display a feedback message

Page 17: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectChapter 27: Updating Users

You need to update a database when information changes in a dataset.Suppose one of your Top Secret users gets a new e-mail address, for example.Changing that user’s e-mail address requires you to connect to the database, locate the user’s record, change the e-mail address in the dataset, and update the database.In Chapter 27, you will learn how to make these kinds of changes in a database.

Page 18: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectUpdate User Script

The update user script performs the following tasks:

Get the user name from the form.Make sure the user name exists.Update the fields in the data table.Update the database.Display a feedback message.

Page 19: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectChapter 28: Deleting Users

In Chapter 28, you will create a Delete button that will enable you to remove users from the database who no longer should have access to your top secret information.When you write the code for the Delete button, you will learn the dataset method for deleting records from a database. This will round out the database functions you have learned in this part of this book.By the time you complete this chapter, you will have learned how to insert, update, retrieve, and delete records from a database.

Page 20: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Top Secret ProjectDelete User Script

The delete user script performs the following tasks:

Get from the form the user name to be deleted.Make sure the user exists.Delete the user from the data table.Update the database.Display a feedback message

Page 21: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Chapter 29: Logging Users In

Design the Login.aspx page, which contains four labels, two text fields, and one button .Code and test the Login button.Make the login button set the authentication cookie.Configure the authentication mode in the Web.config file.

Page 22: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Setting theAuthentication Cookie

To set the authentication cookie, make the code that handles the login button issue the following command if the username and password are valid:System.Web.Security.FormsAuthentication.SetAuthCookie(sUserName, false);False causes the cookie not to get written to the user’s hard drive.

Page 23: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Configuring theAuthentication Mode

Open the project’s Web.config file.Make the <authentication> section read as follows:

<authentication mode="Forms"> <forms loginUrl="login.aspx"></forms></authentication>

This causes unauthenticated users to get the login.aspx page if they try to access any other page in this app.

Page 24: ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn

Identifying the User

When a user has logged on, you can find out the user’s name via the following code:String sUserName = "";if (HttpContext.Current.Request.IsAuthenticated)

sUserName =

HttpContext.Current.User.Identity.Name;