logo资料库

Pro ASP.NET 4.5 in C#(5th) 无水印pdf.pdf

第1页 / 共1198页
第2页 / 共1198页
第3页 / 共1198页
第4页 / 共1198页
第5页 / 共1198页
第6页 / 共1198页
第7页 / 共1198页
第8页 / 共1198页
资料共1198页,剩余部分请下载后查看
Cover
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
分享到:
收藏