pro asp.net 4.5 in c#, 5th edition

1.2K 10.3K 0
pro asp.net 4.5 in c#, 5th edition

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. www.it-ebooks.info v Contents at a Glance About the Author ������������������������������������������������������������������������������������������������������������ xxxv About the Technical Reviewer �������������������������������������������������������������������������������������� xxxvii Acknowledgments ��������������������������������������������������������������������������������������������������������� xxxix Part 1: Getting Started ■ ���������������������������������������������������������������������������������� 1 Chapter 1: Your First ASP�NET Application ■ �������������������������������������������������������������������������3 Chapter 2: Putting ASP�NET in Context ■ ����������������������������������������������������������������������������29 Chapter 3: Essential C# Language Features ■ ��������������������������������������������������������������������37 Chapter 4: Using jQuery ■ ���������������������������������������������������������������������������������������������������75 Chapter 5: Essential Development Tools ■ ������������������������������������������������������������������������101 Chapter 6: SportsStore: A Real Application ■ �������������������������������������������������������������������117 Chapter 7: SportsStore: Navigation & Cart ■ ��������������������������������������������������������������������143 Chapter 8: SportsStore: Completing the Cart ■ ����������������������������������������������������������������173 Chapter 9: SportsStore: Administration ■ ������������������������������������������������������������������������207 Chapter 10: SportsStore: Deployment ■ ���������������������������������������������������������������������������231 Chapter 11: Testable Web Apps ■ �������������������������������������������������������������������������������������247 Part 2: The Core ASP�NET Platform ■ ����������������������������������������������������������� 279 Chapter 12: Working with Web Forms ■ ���������������������������������������������������������������������������281 Chapter 13: Lifecycles and Context ■ �������������������������������������������������������������������������������313 Chapter 14: Modules ■ �����������������������������������������������������������������������������������������������������345 Chapter 15: Handlers ■ �����������������������������������������������������������������������������������������������������369 www.it-ebooks.info ■ Contents at a GlanCe vi Chapter 16: Page and Control Lifecycle Events ■ �������������������������������������������������������������401 Chapter 17: Managing Request Execution ■ ���������������������������������������������������������������������425 Chapter 18: Managing State Data ■ ����������������������������������������������������������������������������������451 Chapter 19: Caching ■ ������������������������������������������������������������������������������������������������������487 Chapter 20: Caching Output ■ �������������������������������������������������������������������������������������������515 Chapter 21: Handling Errors ■ ������������������������������������������������������������������������������������������549 Chapter 22: Managing Paths ■ �����������������������������������������������������������������������������������������581 Chapter 23: URL Routing ■ ������������������������������������������������������������������������������������������������607 Chapter 24: Advanced URL Routing ■ �������������������������������������������������������������������������������639 Chapter 25: Authentication and Authorization ■ ��������������������������������������������������������������667 Chapter 26: Membership ■ �����������������������������������������������������������������������������������������������697 Chapter 27: ASP�NET Configuration ■ ��������������������������������������������������������������������������������725 Chapter 28: Asynchronous Request Handling ■ ���������������������������������������������������������������761 Part 3: Forms and Controls ■ ����������������������������������������������������������������������� 777 Chapter 29: Working with Controls ■ �������������������������������������������������������������������������������779 Chapter 30: Forms and Request Validation ■ �������������������������������������������������������������������813 Chapter 31: Creating Custom Controls ■ ��������������������������������������������������������������������������839 Chapter 32: Stateful Controls ■ ����������������������������������������������������������������������������������������867 Chapter 33: Server-Side HTML Elements ■ �����������������������������������������������������������������������901 Chapter 34: Model Binding ■ ��������������������������������������������������������������������������������������������931 Chapter 35: Data Binding ■ �����������������������������������������������������������������������������������������������961 Chapter 36: Basic Data Controls ■ ������������������������������������������������������������������������������������991 Chapter 37: Complex Data Controls ■ �����������������������������������������������������������������������������1021 Chapter 38: Other ASP�NET Controls ■ ����������������������������������������������������������������������������1051 www.it-ebooks.info ■ Contents at a GlanCe vii Part 4: Client-Side Development ■ ������������������������������������������������������������� 1073 Chapter 39: Managing Scripts and Styles ■ �������������������������������������������������������������������1075 Chapter 40: Ajax and Web Services ■ �����������������������������������������������������������������������������1099 Chapter 41: Client-Side Validation ■ �������������������������������������������������������������������������������1125 Chapter 42: Targeting Mobile Devices ■ �������������������������������������������������������������������������1149 Index �������������������������������������������������������������������������������������������������������������������������������1165 www.it-ebooks.info Part 1 Getting Started We start this book by jumping straight into ASP.NET and creating a simple application. We’ll then explain the C# language features and development tools that are needed for ASP.NET development and use them to create a realistic web application called SportsStore. www.it-ebooks.info 3 Chapter 1 Your First ASP.NET Application The best way to get started with ASP.NET is to jump right in. In this chapter, we will show you how to get set up for ASP.NET development and build your first ASP.NET application. The application we will build is simple, but it allows us to show you how to prepare your workstation for ASP.NET development, how the ASP.NET development tools work, and—most importantly—how quickly you can get up and running with ASP.NET. We’ll provide some context and background about the ASP.NET Framework in the next chapter, but this book focuses on coding so that’s what we are going to start with. Preparing Your Workstation You only need two things for ASP.NET development—a Windows 7 or Windows 8 workstation and Visual Studio, which is the Microsoft development environment. You probably have a Windows installation already, but you can usually find some pretty good deals if you need to buy a copy. Microsoft has discount schemes you can use if you are a student or teacher, or if you want to upgrade schemes from older Windows versions. Microsoft also has subscription schemes if you want wider access to its software products. You can get a 90-day trial of Windows 8 from http://msdn.microsoft.com/en-us/windows/apps if you don’t have Windows and you would like to familiarize yourself with ASP.NET development without making a financial commitment. You need Visual Studio 2012 to build applications with ASP.NET 4.5, the version of the ASP.NET Framework we use in this book. Several different editions of Visual Studio 2012 are available, but we will be using the one that Microsoft makes available free of charge—Visual Studio Express 2012 for Web. Microsoft adds some nice features to the paid-for editions of Visual Studio, but you won’t need them for this book. In addition, all of the figures throughout this book have been taken using the Express edition running on Windows 8. You can download the Express edition from www.microsoft.com/visualstudio/eng/products/visual-studio-express-products. There are several different editions of Visual Studio 2012 Express, each of which is used for a different kind of development—make sure that you get the Web edition, which supports ASP.NET applications. Tip ■ You can use any edition of Visual Studio 2012 for the examples in this book. You will see slight differences in some of the dialog boxes and the menu and toolbar configurations, but otherwise you will be just fine. Creating a New ASP.NET Project Start Visual Studio 2012 and select New Project from the File menu. You will see the New Project dialog box, which, as the name suggests, you use to create new Visual Studio projects. www.it-ebooks.info CHAPTER 1 ■ YOUR FIRST ASP.NET APPLICATION 4 You will see a list of the available project types in the left-hand panel of the dialog box. Navigate to Installed ➤ Templates ➤ Visual C# ➤ Web and you will see the set of ASP.NET projects available, as shown in Figure 1-1. Figure 1-1. The New Project dialog box Tip ■ Make sure you select Visual C# and not Visual Basic. You’ll get some very odd behavior and errors if you try to follow our C# examples in a Visual Basic project. Select the ASP.NET Empty Web Application item from the central panel of the dialog box—some of the names of the different project types are similar so make sure that you get the right one. Make sure that .Net Framework 4.5 is selected in the drop-down menu at the top of the screen and set the Name field to PartyInvites. Click the OK button to create the new project. Tip ■ Visual Studio will set the Solution Name field to PartyInvites to match the project name. A Visual Studio solution is a container for one or more projects, but for all of the examples in this book our solutions will contain just one project, which is typical for ASP.NET Framework development. The ASP.NET Empty Web Application is the simplest of the project templates and creates a project that only contains a Web.config file, which contains the configuration information for your ASP.NET application. Visual Studio shows you files in the Solution Explorer window, which you can see in Figure 1-2. The Solution Explorer is the principal tool for navigating around your project. www.it-ebooks.info CHAPTER 1 ■ YOUR FIRST ASP.NET APPLICATION 5 Adding a New Web Form As you saw when you created the Visual Studio project, there are different kinds of ASP.NET applications. For the type of application we describe in this book, content is generated from a Web Form. This is a misleading name, as we explain in Chapter 2, but for the moment it is enough to know that we add content to our application by adding new Web Form items. To add a new Web Form to the project, right-click the PartyInvites project entry in the Solution Explorer window and select Add ➤ Web Form from the pop-up menu. When prompted, enter Default as the name for the new item, as shown in Figure 1-3. Figure 1-2. The Visual Studio Solution Explorer window Figure 1-3. Setting the name for the new Web Form Note ■ Throughout this book, we build up each example so that you can follow along in your own Visual Studio project. If you don’t want to follow along, you can download a complete set of example projects from apress.com. We have organized the examples by chapter and have included all of the files you will need. Click the OK button to dismiss the dialog and create the new item. You will see that Visual Studio has added a Default.aspx file to the project in the Solution Explorer and opened the file for editing. You can see the initial contents of the file in Listing 1-1. Listing 1-1. The initial contents of the Default.aspx file <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PartyInvites.Default" %> www.it-ebooks.info CHAPTER 1 ■ YOUR FIRST ASP.NET APPLICATION 6 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> </form> </body> </html> A Web Form file is, at its heart, an enhanced HTML file. The element that has the <% and %> tags gives away the fact this isn’t a regular HTML file, as do the runat attributes present in the head and form elements. We’ll explain what all of this means later, but for now we just want to emphasize that we are indeed working with HTML. In Listing 1-2, you can see that we have added some standard HTML elements to the Default.aspx file. Listing 1-2. Adding standard HTML elements to the Default.aspx file <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PartyInvites.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <h1>Hello</h1> <p>This is a new web form</p> </div> </form> </body> </html> We have added an h1 and a p element containing some simple text. Nothing is specific to ASP.NET in these elements—they are standard HTML. Testing the Example Application The Visual Studio toolbar contains a drop-down list with the names of the browsers you have installed on your workstation (click the small down arrow to the right of the name to show the list). You can see our list in Figure 1-4, which shows that we have several browsers installed. At the very least, you will have entries for Internet Explorer and Page Inspector (a tool that helps you debug your HTML and that we demonstrate later in Chapter 5). www.it-ebooks.info [...]... select elements in the Default.aspx file don’t have this attribute/value combination, the model binding process isn’t able to find the values submitted in the HTML form In Listing 1-13, you can see how we have corrected the problem Listing 1-13.  Adding the runat attribute to the input and select elements . styles defined in the PartyStyles.css file #rsvpform label { width: 120px; display: inline-block;} #rsvpform input { margin: 2px; margin-left: 4px; width: 150 px;} #rsvpform select { margin: 2px. 1-9. Listing 1-9. The initial content of the Default.aspx.cs code-behind file using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; . that ASP. NET should use to obtain the values it needs—we have used the System.Web.ModelBinding.FormValueProvider class, which provides values from form data. We describe model binding in more

Ngày đăng: 01/08/2014, 16:43

Từ khóa liên quan

Mục lục

  • Pro ASP.NET 4.5 in C#

    • Contents at a Glance

    • Contents

    • About the Author

    • About the Technical Reviewer

    • Acknowledgments

    • Part 1: Getting Started

      • Chapter 1: Your First ASP.NET Application

        • Preparing Your Workstation

        • Creating a New ASP.NET Project

          • Adding a New Web Form

          • Testing the Example Application

        • Creating a Simple Application

          • Setting the Scene

          • Creating a Data Model and Repository

          • Creating and Styling the Form

          • Handling the Form

            • Creating the HTML Response Files

            • Bringing the HTML Elements into Scope

        • Creating the Summary View

          • Formatting the Dynamic HTML

          • Testing the Dynamic Code

          • Calling a Code-Behind Method

        • Performing Validation

        • Summary

      • Chapter 2: Putting ASP.NET in Context

        • An Overview of the ASP.NET Framework

          • The Evolution and Restructuring of ASP.NET

        • About This Book

          • What Do You Need to Know?

            • What If I Don’t Have That Experience?

          • What Software and Technology Do I Need?

          • Are There Lots of Examples in This Book?

        • The Structure of This Book

          • Part 1: Getting Started

          • Part 2: The Core ASP.NET Platform

          • Part 3: Forms and Controls

          • Part 4: Client-Side Development

        • Understanding Web Forms

          • Understanding Web Forms Strengths

            • Fast to Build, Simple to Use

            • Easy to Recruit Talent

            • Actively Developed, Widely Supported

          • Understanding Web Forms Weaknesses

            • Poor Maintainability

            • Poor Unit Testability

            • Bandwidth-Heavy View State

            • Low Developer Mindshare

        • Summary

      • Chapter 3: Essential C# Language Features

        • Creating the Example Project

        • Using Automatically Implemented Properties

        • Using Object and Collection Initializers

        • Using Extension Methods

          • Applying Extension Methods to an Interface

          • Creating Filtering Extension Methods

        • Using Lambda Expressions

        • Using Automatic Type Inference

        • Using Anonymous Types

        • Using Generic Typing

          • Using a Common Base Class

          • Using Generic Typing

        • Explicitly Implementing Interfaces

        • Performing Language Integrated Queries

          • Understanding Deferred LINQ Queries

        • Using Async Methods

          • Applying the async and await Keywords

        • Summary

      • Chapter 4: Using jQuery

        • Creating the Example Project

          • Adding jQuery to the Example Project

          • Adding jQuery to the Web Form

        • Getting Started with jQuery

          • Waiting for the DOM

          • Understanding jQuery Statements

        • Selecting Elements

          • Selecting Elements by Type, Class, or ID

          • Selecting Elements Using Relationships and Unions

          • Selecting Elements Using Attributes

          • Selecting Elements Using Filters

            • Using Content Filters

            • Using Form Filters

          • Using jQuery Functions

            • Using the DOM Navigation Functions

            • Using the DOM Manipulation Functions

        • Using jQuery Events

        • Working with JSON Data

        • Summary

      • Chapter 5: Essential Development Tools

        • Creating the Example Project

        • Using the Visual Studio Debugger

          • Creating Conditional Breakpoints

          • Understanding the Application State

          • Using the Immediate Window

        • Using the Page Inspector and Browser F12 Tools

          • Using the JavaScript Console

          • Using the Network Monitor

          • Using the JavaScript Profiler

            • Reduce or Reformat the Data

            • Restructure the Client-Side Design

            • Avoid Implementing Native Functions in JavaScript

        • Using NuGet

        • Using Opera Mobile

        • Useful JavaScript Libraries

          • jQuery, jQuery UI, and jQuery Mobile

          • Knockout

          • Modernizr

          • requireJS

        • Summary

      • Chapter 6: SportsStore: A Real Application

        • Creating the Project

          • Creating the Folder Structure

          • Adding the Global Application Class

          • Creating the Database

          • Defining the Database Schema

          • Adding Data to the Database

        • Creating the Data Model and Repository

          • Creating the Data Model Class

          • Adding the Entity Framework

          • Creating the Entity Framework Context

          • Creating the Product Repository

        • Creating the Product Listing

        • Adding Pagination

          • Displaying a Page of Products

          • Adding Pagination Links

        • Styling the List Web Form

          • Creating a Master Page

          • Customizing the Master Page

          • Applying the Master Page

          • Testing the Master Page

        • Summary

      • Chapter 7: SportsStore: Navigation & Cart

        • Configuring URL Routing

          • Creating the Routing Configuration Class

          • Updating the Global Application Class

          • Using Routing Variable s

          • Testing the Routing Configuration

          • Generating Routed Links

        • Adding the Category Information

          • Creating the User Control

          • Applying the User Control to the Master Page

          • Adding the CSS Styles

          • Expanding the URL Scheme

          • Adding Support for Displaying Categories

          • Highlighting the Current Category

        • Building the Shopping Cart

          • Defining the Cart Class

          • Adding the Cart Buttons

            • Using Server Controls and Data Binding

            • Making the Data Method Public

            • Adding the Cart Button CSS

          • Creating a Session Helper

          • Handling the Form Post

          • Displaying the Contents of the Cart

          • Testing the Cart

        • Summary

      • Chapter 8: SportsStore: Completing the Cart

        • Removing Unwanted Cart Items

          • Understanding View State

          • Disabling View State

        • Adding the Cart Summary

          • Defining the CSS Styles

          • Applying the Cart Summary Control

          • Consolidating User Control Declarations

        • Submitting Orders

          • Extending the Database and Data Model

            • Adding Data Model Classes

            • Extending the Context and Repository Classes

          • Adding the Checkout Link and URL

          • Processing the Order

        • Adding Validation

          • Adding the NuGet Packages

            • Updating the Packages

          • Creating and Using a Script Bundle

          • Setting up Client-Side Validation

          • Creating a Server Control

          • Applying the Server Control

        • Summary

      • Chapter 9: SportsStore: Administration

        • Adding the Common Building Blocks

          • Extending the Routing Configuration

          • Adding the Admin Master Page

          • Adding the CSS Style Sheet

          • Adding a Web Form

        • Adding Order Management

          • Cleansing and Populating the Database

          • Adding the Web Form Content

            • Understanding the Data-Binding Expressions

            • Data Binding and Placeholders

            • Understanding the CheckBox Control

          • Creating the Code-Behind Class

        • Adding Catalog Management

          • Extending the Repository

          • Adding the Web Form

          • Setting up the CRUD Methods

          • Testing Catalog Management

        • Setting up Authorization

          • Securing the Administration Pages

          • Creating the Authentication Login Web Form

          • Testing Failed Authentication

          • Testing Successful Authentication and Authorization

        • Summary

      • Chapter 10: SportsStore: Deployment

        • Disabling Debug Mode for Final Testing

        • Preparing Windows Azure

          • Creating the Web Site and Database

          • Preparing the Database for Remote Administration

          • Creating the Schema

            • Getting the Schema Command

            • Adding the Table Data

        • Deploying the Application

        • Summary

      • Chapter 11: Testable Web Apps

        • Understanding the Problem

        • Understanding the Solution

          • Why Not Just Use MVC?

        • Creating the Example Project

          • Setting Up the Static Content

          • Setting Up the Data Model

          • Implementing the Repository

          • Adding the Infrastructure

        • Implementing the RSVP Page

          • Creating the Presenter

          • Creating the View

          • Testing the RSVP Page

        • Adding Unit Testing

          • Creating the Unit Test Project

          • Creating Unit Tests

        • Adding Dependency Injection

          • Adding the Ninject Package

          • Configuring Injection

        • Completing the Application

          • Creating the Presenter

          • Configuring Dependency Injection

        • Summary

    • Part 2: The Core ASP.NET Platform

      • Chapter 12: Working with Web Forms

        • Creating the Example Project

        • Understanding the Web Form File

          • Using Code Nuggets

            • Using Standard Code Nuggets

            • Using Content Code Nuggets

            • Using Data Binding Code Nuggets

            • Using Property Code Nuggets

            • Using Directives

          • Understanding Programmable HTML Elements

          • Understanding Controls

        • Understanding Code-Behind Classes

          • Avoiding Duplication in Code-Behind Classes

        • Understanding How a Web Form Works

          • Handling Programmable HTML Elements

          • Compiling the Web Form

        • Using Master Pages

          • Configuring Master Pages

          • Understanding Master Page Placeholders

          • Applying the Master Page

          • Using the Master Page Code-Behind Class

          • Nesting Master Pages

        • Summary

      • Chapter 13: Lifecycles and Context

        • Creating the Example Project

          • Understanding the Global Application Class

        • Understanding the Application Lifecycle

        • Understanding the Request Lifecycle

          • Understanding Modules and Handlers

          • Handling Request Lifecycle Events

          • Handling Multiple Events in a Method

        • Understanding Context Objects

          • Working with HttpContext Objects

          • Working with HttpApplication Objects

            • Handling Property Exceptions

            • Completing Requests

          • Working with HttpRequest Objects

          • Working with HttpResponse Objects

        • Putting It All Together

          • Timing the Request

          • Restricting Access

          • Logging the Request

        • Summary

      • Chapter 14: Modules

        • Preparing the Example Application

        • Understanding Modules

          • Creating a Module

          • Registering a Module

        • Creating a Module Project

          • Creating the Visual Studio Project

          • Creating the Modules

          • Registering the Modules

        • Working with Module Events

          • Defining the Module Event

          • Handling the Module Event

            • Locating Another Module

          • Locating Modules by Name

        • Working with the Built-In Modules

        • Putting It All Together

        • Summary

      • Chapter 15: Handlers

        • Preparing the Example Application

        • Understanding Handlers

        • Handlers and the Request Lifecycle

        • Creating a Generic Handler

          • Implementing Custom Behavior

          • Testing the Generic Handler

        • Creating Custom Handlers

          • Creating a Custom Handler

          • Registering a Custom Handler

        • Creating Custom Handler Factories

          • Controlling Handler Instantiation

          • Selecting Handlers Dynamically

          • Recycling Handlers

        • Coordinating between Modules and Handlers

          • Using the Items Collection

            • Creating the Module

            • Creating the Handler

          • Using Declarative Interfaces

        • Putting It All Together

          • Finding the Right Built-In Handler Factory

          • Building on the Base Class

          • Writing the Handler

          • Registering the Handler Factory

          • Testing the Handler Factory

        • Summary

      • Chapter 16: Page and Control Lifecycle Events

        • Preparing the Example Application

        • Understanding the Page Class

          • Recreating the Handler Factory

        • Understanding the Page Lifecycle

          • Handling the Page Events

        • Handling Control Events

          • Creating a Simple Control

          • Registering and Applying the Control

        • Receiving Control Events

          • Handling the Control Event

            • Using a Declarative Handler

        • Understanding the End-to-End Web Lifecycle

        • The Page Context

          • Getting Access to Context Objects

          • Setting the Page Directive Values

          • Providing Web Form-Specific Information

            • The IsPostBack Property and HTTP Verbs

        • Putting It All Together

        • Summary

      • Chapter 17: Managing Request Execution

        • Preparing the Example Application

        • Using URL Redirection

          • Performing URL Redirection

          • Manually Performing Redirections

        • Managing Handler Selection and Execution

          • Preempting Handler Selection

          • Transferring a Request

          • Composing Responses by Explicitly Executing Handlers

        • Putting It All Together

          • Creating the Source Code View Handler

          • Using an HTTP Redirection

          • Remapping the Handler

          • Executing Multiple Handlers

            • Creating the Result Web Form

            • Preparing the Source Handler

            • Creating the Side-By-Side Handler

            • Testing the Handler

        • Summary

      • Chapter 18: Managing State Data

        • Creating the Example Application

        • Understanding State Data

        • Storing Application Data

        • Storing User Data

          • Creating the Profile Database

            • Checking the Database

          • Configuring the Database Connection

          • Configuring Profiles and Profile Properties

          • Defining Profile Providers

          • Defining Profile Properties

          • Using Profile Data

        • Storing Session Data

          • Using Session Data

          • Configuring Session Data

          • Using the State Server

          • Using a SQL Database

            • Creating the Session Database

            • Using the Session Database

        • Using View Data

          • Configuring View State

        • Using Cookies

        • Putting It All Together

          • Creating the Module

          • Creating the Web Form

        • Summary

      • Chapter 19: Caching

        • Preparing the Example Application

        • Using the Application Cache

        • Managing Item Caching

        • Caching with Dependencies

          • Caching with an Internal Dependency

          • Creating a Custom Dependency

          • Caching with Aggregate Dependencies

          • Caching with Expiration Constraints

          • Caching with Scavenging Prioritization

        • Receiving Cache Notifications

          • Receiving Notification of Cache Ejection

            • Performing Eager Cache Updates

          • Using Notifications to Prevent Cache Ejection

        • Configuring Caching

        • Putting It All Together

        • Summary

      • Chapter 20: Caching Output

        • Preparing the Example Application

        • Caching Web Form Output

          • Controlling End-to-End Caching

          • Caching Multiple Copies of Content

            • Caching Multiple Copies Based on Headers

            • Caching Multiple Copies for Other Reasons

          • Creating Cache Profiles

        • Selectively Updating Content

        • Caching User Control Output

          • Caching Multiple Copies Based on Nested Controls

        • Caching Server Control Output

        • Creating Cache Dependencies

        • Using a Custom Output Cache

          • Creating the Custom Cache Implementation

          • Registering the Custom Output Cache Implementation

          • Dynamically Selecting an Output Cache Implementation

        • Configuring the Output Cache

        • Putting It All Together

          • Creating the Handler Factory Class

            • Caching Responses

            • Processing Requests

          • Registering the Handler Factory

        • Summary

      • Chapter 21: Handling Errors

        • Preparing the Example Project

        • Understanding Errors

        • Customizing the Default Behavior

          • Providing a Catchall Error Page

            • Creating a Dynamic Error Page

          • Handling Specific HTTP Errors

            • Dealing with ASP.NET HTTP Status Code s

            • Dealing with IIS HTTP Status Code s

            • Creating a Shared Dynamic Error Page

          • Specifying an Error Page Specific to a Web Form

        • Taking Control of the Error Handling Process

          • Handling the Error in the Web Form

          • Handling the Error at the Application Level

            • Clearing the Precedence Path

            • Implementing the Application-Level Error Handler

          • Handling Errors without Redirection

        • Handling Multiple Errors

          • Reporting the Errors

          • Displaying the Errors

          • Intercepting the Errors

        • Putting It All Together

          • Removing the Existing Error Handling Code

          • Defining the Module

        • Summary

      • Chapter 22: Managing Paths

        • Preparing the Example Project

          • Creating a Module

          • Creating Additional Content

        • Working with Paths

          • Getting Path Information

            • Getting Fixed and Dynamic Path Information

            • Dealing with Additional Path Information

          • Manipulating Paths

        • Managing Virtual Paths

          • Setting Default Documents

          • Handling Requests for Extensionless URLs

          • Rewriting Paths

        • Using the Friendly URLs Package

          • Disabling the Previous Examples

          • Installing and Configuring the NuGet Package

          • Using the FriendlyUrls Library Features

            • Using the Extension Methods

            • Model Binding to Path Info Segments

        • Putting It All Together

          • Writing Files

          • Rewriting Paths

        • Summary

      • Chapter 23: URL Routing

        • Preparing the Example Project

        • Preparing the Application for Routing

        • Working with Fixed Routes

          • Getting Route Information

        • Adding Variable Segments

          • Dealing with Over-Eager Routes

            • Applying Routing Constraints

          • Creating Hackable URLs

            • Defining Default Values

          • Creating Variable-Length Segments

        • Model Binding to Route Segment Values

        • Generating Outgoing URLs

          • Manually Generating Outgoing URLs

        • Putting It All Together

          • Generating the Diagnostic HTML

          • Testing URL Matching

        • Summary

      • Chapter 24: Advanced URL Routing

        • Preparing the Example Project

        • Using Advanced Constraints

          • Restricting a Route by HTTP Method

          • Creating a Custom Route Restriction

        • Routing Requests for Files

          • Disabling File Requests for Individual Routes

        • Working with Routing Handlers

          • Preventing Routing for a Request

            • Selectively Filtering Requests

          • Creating a Custom Route Handler

        • Creating a Custom RouteBase Implementation

        • Putting It All Together

          • Disabling ASPX Requests

          • Routing to Other File Types

            • Creating the Route Handler

            • Registering the Routes

          • Letting ASP.NET Select the Route for an Outgoing URL

            • Changing the Route Order

            • Adding a Custom Directional Constraint

        • Summary

      • Chapter 25: Authentication and Authorization

        • Preparing the Example Project

        • Understanding Forms Authentication

        • Configuring ASP.NET Authentication

        • Performing Authentication

          • Authenticating the User

          • Getting Authentication Information

        • Performing Authorization

          • Understanding Authorization and Authentication Integration

            • Testing Authentication Redirection

          • Creating an Authorization Policy

            • Creating a Simple Role Provider

            • Creating the Policy

          • Creating Location-Specific Authorization Policies

            • Creating a Location-Specific Web.config File

        • Bypassing Authorization

        • Authorization Routed URLs

        • Putting It All Together

          • Rebuilding the Authentication Web Form

          • Adding a Master Page

            • Applying the Master Page to the Web Forms

          • Testing the Revised Authorization and Authentication

        • Summary

      • Chapter 26: Membership

        • Preparing the Example Project

        • Adding Membership to the Application

          • Installing the Universal Providers

          • Configuring the Application for Membership

            • Adjusting the Configuration

          • Creating Users and Roles

          • Performing Authentication Using Membership

        • Using Membership

          • Performing Password Change

          • Performing Password Recovery

            • Integrating Password Recovery into Password Change

          • Performing Registration

            • Creating the User Account

            • Putting the User in Roles

            • Integrating Registration

        • Putting It All Together

        • Summary

      • Chapter 27: ASP.NET Configuration

        • Preparing the Example Project

        • Understanding the Configuration Hierarchy

        • Getting Configuration Information Programmatically

          • Working with Application Settings

            • Overriding Application Settings

          • Working with Connection Strings

            • Making a Database Connection Using a Connection String

          • Working with Configuration Sections

            • Getting a Single Section

          • Working with the Complete Configuration

        • Creating Custom Configuration Sections and Groups

          • Creating a Simple Configuration Section

            • Creating the Section Handler Class

            • Defining the Section

            • Using the Custom Configuration Section

          • Creating a Collection Configuration Section

            • Defining the Section

            • Using the Collection Configuration Section

          • Creating a Configuration Section Group

        • Using External Configuration Files

        • Locking Configuration Sections

        • Putting It All Together

        • Summary

      • Chapter 28: Asynchronous Request Handling

        • Preparing the Example Project

        • Understanding the Problem

        • Creating an Asynchronous Web Form

          • Using an Asynchronous Method

          • Creating and Registering the Asynchronous Page Task

          • Performing Multiple Tasks

        • Creating Asynchronous Modules

        • Creating Asynchronous Handlers

        • Summary

    • Part 3: Forms and Controls

      • Chapter 29: Working with Controls

        • Preparing the Example Project

        • Understanding Controls

          • Understanding the Base Control Class

          • Using Controls for Programmatic Access to HTML Elements

          • Using Custom Controls to Generate Fragments of HTML

            • Nesting Controls

            • Shared State and Request Handling

            • Single Form Element

          • Using Custom Server Controls

          • Using Controls to Display Data

          • Using Controls to Model Desktop Development

        • Working with the Control Hierarchy

          • Navigating the Control Hierarchy

          • Locating and Manipulating Controls in the Hierarchy

            • Understanding the Button Label Duplication Problem

          • Adding Controls Programmatically

        • Putting It All Together

          • Removing the Rich UI Controls

        • Summary

      • Chapter 30: Forms and Request Validation

        • Preparing the Example Project

          • Adding jQuery

        • Understanding the Server-Side Form Element

          • Using the DefaultButton and DefaultFocus Properties

            • Getting a Better Result

        • Detecting Form Posts and Postbacks

          • Looking for Form Data in the Query String

          • Checking for POST Requests

        • Working with Form Data

        • Understanding the One-Form Limit

        • Understanding Request Validation

          • Using Eager Request Validation

          • Using Lazy Request Validation

          • Using Unvalidated Form Data

            • Displaying Dangerous Data

          • Request Validation in Controls

        • Putting It All Together

        • Summary

      • Chapter 31: Creating Custom Controls

        • Preparing the Example Project

          • Adding jQuery

        • Creating a Basic Control

          • Understanding the Control Directive

          • Registering and Applying a Control

            • Using the Register Directive

            • Applying the Control

          • Registering a Control in the Web.config File

        • Adding Functionality to the Control

        • Understanding Control IDs

          • Identifying HTML Elements Generated by Controls

          • Identifying Controls within the Control Hierarchy

        • Defining Element Attributes

          • Creating Enumeration Attributes

          • Creating Collection Attributes

        • Creating a Server Control

          • Registering a Server Control

          • Using the HtmlTextWriter Class

            • Writing Constrained HTML

            • Writing Unconstrained HTML

        • Putting It All Together

        • Summary

      • Chapter 32: Stateful Controls

        • Preparing the Example Project

          • Registering and Applying the User Control

        • Understanding Statelessness and the Control Lifecycle

          • Using Session State

          • Adding State through Form Elements

          • Using View State

          • Using Control State

        • Managing Application View State

          • Configuring Application View State

            • Measuring View State

          • Configuring Web Form and Control View State

          • Configuring Control View State

            • Selectively Disabling View State

            • Selectively Enabling View State

        • Putting It All Together

          • Using View State for Input Elements

            • Solving the Problem

          • Using View State in Child Controls

            • Preventing View State Duplication

          • Adding to View State Data

          • Confusing View State and Control State

        • Summary

      • Chapter 33: Server-Side HTML Elements

        • Preparing the Example Project

        • Understanding Server-Side Elements

          • Using the Base Class Features

          • Using Container Elements

            • Setting the Content of Container Elements

        • Working with Page Structure Elements

        • Working with Form Elements

          • Working with the input Element

            • Working with the Type-Specific Control Classes

            • Using HTML5 Form Features

          • Working with Other Form Elements

        • Working with HTML Tables

          • Enumerating the Table

            • Changing the Cell Values

          • Working with Specific Table Elements

          • Creating Tables Programmatically

        • Working with Other Elements

        • Putting It All Together

        • Summary

      • Chapter 34: Model Binding

        • Preparing the Example Project

        • Understanding the Problem

        • Applying Model Binding

          • Applying Model Validation Attributes

            • Using a Custom Validation Method

        • Handling Model Binding and Validation Errors

          • Using the Validation Summary

        • Using Binding Attributes

          • Applying Model Binding Attributes

          • Using Model Binding Attributes for Complex Types

        • Putting It All Together

          • Creating Self-Validating Model Classes

          • Creating Field-Level Error Controls

        • Summary

      • Chapter 35: Data Binding

        • Preparing the Example Project

        • Understanding Data Binding

          • Configuring Data Binding

            • Specifying the Data Item Type

            • Specifying the Source of the Data

            • Binding Data Values

            • Manipulating Data from Data Binding Methods

          • Combining Elements and Data Controls

            • Managing State via Data Projection

            • Using a Different Control

        • Writing a Custom Data Control

          • Managing Data Control View State

          • Adding a Template to a Custom Data Control

            • Enabling the Item Keyword

            • Defining the Template Container

            • Implementing the Template Property

            • Applying the Template

            • Applying the Template to the Control

          • Adding Features to the Template

        • Putting It Together

        • Summary

      • Chapter 36: Basic Data Controls

        • Selecting a Data Control

        • Preparing the Example Project

          • Adding jQuery

        • Using the List Data Controls

          • Using the CheckBoxList Control

            • Controlling the Element Layout

            • Handling Selections

            • Handling Control Events

            • Dealing with Generated Elements in Client Scripts

          • Using the DropDownList Control

          • Using the ListBox Control

          • Using the RadioButtonList Control

          • Using the BulletedList Control

        • Using the Repeater Control

          • Our Standard Repeater Usage

          • Using the Repeater Templates

          • Creating Templates Programmatically

        • Putting It All Together

        • Summary

      • Chapter 37: Complex Data Controls

        • Preparing the Example Project

          • Preparing Script Management

          • Extending the CSS

        • Using the FormView Control

          • Defining the Code-Behind Class

          • Defining the Templates

          • Managing the Outer Element

          • Editing Data with the FormView Control

            • Specifying the Data Methods

            • Switching Editing Modes

            • Defining the Edit Template

          • Implementing the Data Methods

          • Understanding FormView Events

        • Using the ListView Control

          • Using the Basic ListView Functionality

            • Declaring the Control

            • Defining the Templates

          • Sorting Data with the ListView Control

          • Paging Data

          • Understanding ListView Events

        • Putting It All Together

        • Summary

      • Chapter 38: Other ASP.NET Controls

        • Preparing the Example Application

        • Working with the Rich UI Controls

          • Rich UI Controls Are Unnecessary Abstractions

          • Rich UI Controls Modify Element Behavior

          • Rich UI Controls Rely on C# Events

          • Rich UI Controls Are Styled Directly

        • Selecting a Rich UI Control

          • Understanding Core Rich UI Control Features

            • Understanding Control Events

            • Understanding Control Commands

            • Understanding Cross-Page Posting

        • Using the Odds-and-Ends Controls

          • Using the Literal Control

          • Using the PlaceHolder Control

          • Using the MultiView Control

        • Putting It All Together

        • Summary

    • Part 4: Client-Side Development

      • Chapter 39: Managing Scripts and Styles

        • Preparing the Example Project

        • Understanding Script Management Issues

          • Managing JavaScript File Versioning

          • Managing Library Dependencies

          • Managing Minification

        • Using Bundles

          • Preparing the Project for Bundles

          • Creating a Script Bundle

            • Applying a Script Bundle

            • Avoiding Bundle File Duplication

          • Creating a Style Bundle

        • Using Bundling Optimizations

          • Using Local Optimization

            • Fixing the File Duplication Issue

            • Fixing the Relative Image Issue

          • Using Content Delivery Networks

        • Ensuring Libraries Are Available for Controls

        • Putting It All Together

        • Summary

      • Chapter 40: Ajax and Web Services

        • Preparing the Example Project

        • Creating Web Services Using Web API

          • Understanding the Goal

          • Creating the Web API Controller

          • Creating the Routing Configuration

          • Testing the Web Service

          • Implementing the Controller Methods

            • Fixing the Serialization Issue

        • Consuming the Web Service

          • Dealing with Model Validation Errors

        • Dealing with Event Validation

          • Disabling Event Validation

          • Replacing the Control

        • Putting It All Together

        • Summary

      • Chapter 41: Client-Side Validation

        • Preparing the Example Project

          • Installing the JavaScript Packages

          • Creating the Validation Script Bundle

        • Using HTML5 Validation

        • Using the Built-In Validation Controls

        • Applying Validation Attributes Directly

          • Defining the Validation Policy

        • Removing Validation Policy Duplication

        • Putting It All Together

          • Updating the Web Service

          • Updating the Model Object

          • Creating the JavaScript

        • Summary

      • Chapter 42: Targeting Mobile Devices

        • Preparing the Example Project

          • Adding the jQuery Mobile Package

        • Identifying Mobile Devices

        • Switching Master Pages for Mobile Devices

          • Applying JavaScript Libraries via the Master Page

        • Delivering Different Web Forms

          • Installing and Configuring the Package

          • Delivering Custom Content

          • Allowing the User to Choose

        • Putting It All Together

        • Summary

    • Index

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan