Freeman | Pro ASP.NET Core MVC 2 | E-Book | www2.sack.de
E-Book

E-Book, Englisch, 1017 Seiten

Freeman Pro ASP.NET Core MVC 2


7th ed
ISBN: 978-1-4842-3150-0
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

E-Book, Englisch, 1017 Seiten

ISBN: 978-1-4842-3150-0
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



Now in its 7th edition, the best selling book on MVC is updated for ASP.NET Core MVC 2. It contains detailed explanations of the Core MVC functionality which enables developers to produce leaner, cloud optimized and mobile-ready applications for the .NET platform. This book puts ASP.NET Core MVC into context and dives deep into the tools and techniques required to build modern, cloud optimized extensible web applications. All the new MVC features are described in detail and the author explains how best to apply them to both new and existing projects.

The ASP.NET Core MVC Framework is the latest evolution of Microsoft’s ASP.NET web platform, built on a completely new foundation. It represents a fundamental change to how Microsoft constructs and deploys web frameworks and is free of the legacy of earlier technologies such as Web Forms. ASP.NET Core MVC provides a "host agnostic" framework and a high-productivity programming model that promotes cleaner code architecture, test-driven development, and powerful extensibility.

Best-selling author Adam Freeman has thoroughly revised this market-leading book and explains how to get the most from ASP.NET Core MVC. He starts with the nuts-and-bolts and shows you everything through to advanced features, going in-depth to give you the knowledge you need. The book includes a fully worked case study of a functioning web application that readers can use as a template for their own projects.

What's New in This Edition

  • Fully updated for Visual Studio 2017, C# 7 and .NET Core 2
  • Coverage of new features such as view filters
  • Wider platform and tooling coverage than ever before, with more on Visual Studio Code and working with .NET Core on non-Windows platforms
  • Docker-based application deployment

What You Will Learn

  • Gain a solid architectural understanding of ASP.NET Core MVC
  • Explorethe entire ASP.NET MVC Framework as a cohesive whole
  • See how MVC and test-driven development work in action
  • Learn what's new in ASP.NET Core MVC 2 and how best to apply these new features to your own work
  • See how to create RESTful web services and Single Page Applications
  • Build on your existing knowledge of previous MVC releases to get up and running with the new programming model quickly and effectively

Who This Book Is For

This book is for web developers with a basic knowledge of ASP.NET and C# who want to incorporate the latest improvements and functionality in the ASP.NET Core MVC 2 Framework.



Freeman Pro ASP.NET Core MVC 2 jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


1;Contents at a Glance;5
2;Contents;7
3;About the Author;27
4;About the Technical Reviewer;28
5;Part I: Introducing ASP.NET Core MVC 2;29
5.1;Chapter 1: ASP .NET Core MVC in Context;30
5.1.1;Understanding the History of ASP.NET Core MVC;30
5.1.1.1;ASP.NET Web Forms;31
5.1.1.1.1;What Was Wrong with ASP.NET Web Forms?;31
5.1.1.2;The Original MVC Framework;32
5.1.1.2.1;What Was Wrong with the Original MVC Framework?;32
5.1.2;Understanding ASP.NET Core;32
5.1.2.1;What’s New in ASP.NET Core MVC 2;33
5.1.2.2;Key Benefits of ASP.NET Core MVC;33
5.1.2.2.1;MVC Architecture;33
5.1.2.2.2;Extensibility;34
5.1.2.2.3;Tight Control over HTML and HTTP;34
5.1.2.2.4;Testability;34
5.1.2.2.5;Powerful Routing System;35
5.1.2.2.6;Modern API;35
5.1.2.2.7;Cross-Platform;35
5.1.2.2.8;ASP.NET Core MVC Is Open Source;36
5.1.3;What Do I Need to Know?;36
5.1.4;What Is the Structure of This Book?;36
5.1.4.1;Part 1: Introducing ASP.NET Core MVC;36
5.1.4.2;Part 2: ASP.NET Core MVC in Detail;36
5.1.5;Where Can You Get the Example Code?;36
5.1.6;Where Can You Get Corrections for This Book?;37
5.1.7;Contacting the Author;37
5.1.8;Summary;37
5.2;Chapter 2: Your First MVC Application;38
5.2.1;Installing Visual Studio;38
5.2.2;Installing the .NET Core 2.0 SDK;39
5.2.3;Creating a New ASP.NET Core MVC Project;40
5.2.3.1;Adding the Controller;44
5.2.3.2;Understanding Routes;47
5.2.4;Rendering Web Pages;47
5.2.4.1;Creating and Rendering a View;47
5.2.4.2;Adding Dynamic Output;50
5.2.5;Creating a Simple Data-Entry Application;52
5.2.5.1;Setting the Scene;52
5.2.5.2;Designing a Data Model;53
5.2.5.3;Creating a Second Action and a Strongly Typed View;54
5.2.5.4;Linking Action Methods;56
5.2.5.5;Building the Form;57
5.2.5.6;Receiving Form Data;59
5.2.5.6.1;Using Model Binding;60
5.2.5.6.2;Storing Responses;61
5.2.5.7;Displaying the Responses;64
5.2.5.8;Adding Validation;66
5.2.5.8.1;Highlighting Invalid Fields;70
5.2.5.9;Styling the Content;72
5.2.5.9.1;Styling the Welcome View;72
5.2.5.9.2;Styling the RsvpForm View;74
5.2.5.9.3;Styling the Thanks View;76
5.2.5.9.4;Styling the List View;77
5.2.6;Summary;78
5.3;Chapter 3: The MVC Pattern, Projects, and Conventions;79
5.3.1;The History of MVC;79
5.3.2;Understanding the MVC Pattern;79
5.3.2.1;Understanding Models;79
5.3.2.2;Understanding Controllers;80
5.3.2.3;Understanding Views;81
5.3.2.4;The ASP.NET Implementation of MVC;81
5.3.3;Comparing MVC to Other Patterns;82
5.3.3.1;Understanding the Smart UI Pattern;82
5.3.3.2;Understanding the Model-View Architecture;83
5.3.3.3;Understanding Classic Three-Tier Architecture;84
5.3.3.4;Understanding Variations on MVC;85
5.3.3.4.1;Understanding the Model-View-Presenter Pattern;85
5.3.3.4.2;Understanding the Model-View-View Model Pattern;85
5.3.4;Understanding ASP.NET Core MVC Projects;86
5.3.4.1;Creating the Project;86
5.3.4.2;Understanding MVC Conventions;89
5.3.4.2.1;Following Conventions for Controller Classes;90
5.3.4.2.2;Following Conventions for Views;90
5.3.4.2.3;Following Conventions for Layouts;91
5.3.5;Summary;91
5.4;Chapter 4: Essential C# Features;92
5.4.1;Preparing the Example Project;93
5.4.1.1;Enabling ASP.NET Core MVC;94
5.4.1.2;Creating the MVC Application Components;95
5.4.1.2.1;Creating the Model;95
5.4.1.2.2;Creating the Controller and View;96
5.4.2;Using the Null Conditional Operator;98
5.4.2.1;Chaining the Null Conditional Operator;99
5.4.2.2;Combining the Conditional and Coalescing Operators;100
5.4.3;Using Automatically Implemented Properties;101
5.4.3.1;Using Auto-Implemented Property Initializers;102
5.4.3.2;Creating Read-Only Automatically Implemented Properties;103
5.4.4;Using String Interpolation;104
5.4.5;Using Object and Collection Initializers;105
5.4.5.1;Using an Index Initializer;107
5.4.6;Pattern Matching;108
5.4.6.1;Pattern Matching in Switch Statements;109
5.4.7;Using Extension Methods;110
5.4.7.1;Applying Extension Methods to an Interface;111
5.4.7.2;Creating Filtering Extension Methods;113
5.4.8;Using Lambda Expressions;115
5.4.8.1;Defining Functions;116
5.4.8.2;Using Lambda Expression Methods and Properties;119
5.4.9;Using Type Inference and Anonymous Types;121
5.4.9.1;Using Anonymous Types;122
5.4.10;Using Asynchronous Methods;124
5.4.10.1;Working with Tasks Directly;124
5.4.10.2;Applying the async and await Keywords;126
5.4.11;Getting Names;127
5.4.12;Summary;129
5.5;Chapter 5: Working with Razor;130
5.5.1;Preparing the Example Project;131
5.5.1.1;Defining the Model;132
5.5.1.2;Creating the Controller;132
5.5.1.3;Creating the View;133
5.5.2;Working with the Model Object;134
5.5.2.1;Using View Imports;136
5.5.3;Working with Layouts;137
5.5.3.1;Creating the Layout;138
5.5.3.2;Applying a Layout;140
5.5.3.3;Using a View Start File;141
5.5.4;Using Razor Expressions;143
5.5.4.1;Inserting Data Values;144
5.5.4.2;Setting Attribute Values;146
5.5.4.3;Using Conditional Statements;147
5.5.4.4;Enumerating Arrays and Collections;149
5.5.5;Summary;151
5.6;Chapter 6: Working with Visual Studio;152
5.6.1;Preparing the Example Project;152
5.6.1.1;Creating the Model;153
5.6.1.2;Creating the Controller and View;154
5.6.2;Managing Software Packages;156
5.6.2.1;Understanding NuGet;156
5.6.2.1.1;Understanding the NuGet Packages List and Location;157
5.6.2.2;Understanding Bower;158
5.6.2.2.1;Understanding the Bower Packages List;158
5.6.2.2.2;Updating the Bootstrap Package;162
5.6.3;Understanding Iterative Development;162
5.6.3.1;Making Changes to Razor Views;163
5.6.3.2;Making Changes to C# Classes;164
5.6.3.2.1;Compiling Classes Automatically;164
5.6.3.2.2;Enabling Developer Exception Pages;166
5.6.3.2.3;Using the Debugger;167
5.6.3.2.3.1;Setting a Breakpoint;168
5.6.3.2.3.2;Viewing Data Values in the Code Editor;169
5.6.3.2.3.3;Using the Locals Window;171
5.6.3.3;Using Browser Link;172
5.6.3.3.1;Setting Up Browser Link;172
5.6.3.3.2;Using Browser Link;173
5.6.3.3.3;Using Multiple Browsers;175
5.6.4;Preparing JavaScript and CSS for Deployment;177
5.6.4.1;Enabling Static Content Delivery;178
5.6.4.2;Adding Static Content to the Project;178
5.6.4.3;Updating the View;181
5.6.4.4;Bundling and Minifying in MVC Applications;182
5.6.4.4.1;Installing the Visual Studio Extension;182
5.6.4.4.2;Bundling and Minifying Files;183
5.6.5;Summary;186
5.7;Chapter 7: Unit Testing MVC Applications;187
5.7.1;Preparing the Example Project;188
5.7.1.1;Enabling the Built-in Tag Helpers;188
5.7.1.2;Adding Actions to the Controller;188
5.7.1.3;Creating the Data Entry Form;189
5.7.1.4;Updating the Index View;190
5.7.2;Unit Testing MVC Applications;191
5.7.2.1;Creating a Unit Test Project;192
5.7.2.1.1;Removing the Default Test Class;193
5.7.2.2;Creating the Project Reference;193
5.7.2.3;Writing and Running Unit Tests;193
5.7.2.3.1;Running Tests with the Test Explorer;196
5.7.2.4;Isolating Components for Unit Testing;198
5.7.2.4.1;Isolating a Component;199
5.7.3;Improving Unit Tests;206
5.7.3.1;Parameterizing a Unit Test;206
5.7.3.1.1;Getting Test Data from a Method or Property;207
5.7.3.2;Improving Fake Implementations;210
5.7.3.2.1;Adding a Mocking Framework;211
5.7.3.2.2;Creating a Mock Object;213
5.7.4;Summary;215
5.8;Chapter 8: SportsStore: A Real Application;216
5.8.1;Getting Started;217
5.8.1.1;Creating the MVC Project;217
5.8.1.1.1;Creating the Folder Structure;218
5.8.1.1.2;Configuring the Application;219
5.8.1.2;Creating the Unit Test Project;221
5.8.1.3;Checking and Running the Application;222
5.8.2;Starting the Domain Model;223
5.8.2.1;Creating a Repository;224
5.8.2.2;Creating a Fake Repository;225
5.8.2.3;Registering the Repository Service;225
5.8.3;Displaying a List of Products;226
5.8.3.1;Adding a Controller;227
5.8.3.2;Adding and Configuring the View;228
5.8.3.3;Setting the Default Route;230
5.8.3.4;Running the Application;231
5.8.4;Preparing a Database;231
5.8.4.1;Installing the Entity Framework Core Tools Package;232
5.8.4.2;Creating the Database Classes;233
5.8.4.3;Creating the Repository Class;233
5.8.4.4;Defining the Connection String;234
5.8.4.5;Configuring the Application;235
5.8.4.5.1;Disabling Scope Verification;236
5.8.4.6;Creating the Database Migration;237
5.8.4.7;Creating the Seed Data;238
5.8.5;Adding Pagination;241
5.8.5.1;Displaying Page Links;243
5.8.5.1.1;Adding the View Model;243
5.8.5.1.2;Adding the Tag Helper Class;244
5.8.5.1.3;Adding the View Model Data;247
5.8.5.1.4;Displaying the Page Links;250
5.8.5.2;Improving the URLs;252
5.8.6;Styling the Content;254
5.8.6.1;Installing the Bootstrap Package;254
5.8.6.2;Applying Bootstrap Styles to the Layout;255
5.8.6.3;Creating a Partial View;258
5.8.7;Summary;259
5.9;Chapter 9: SportsStore: Navigation;260
5.9.1;Adding Navigation Controls;260
5.9.1.1;Filtering the Product List;260
5.9.1.2;Refining the URL Scheme;265
5.9.1.3;Building a Category Navigation Menu;269
5.9.1.3.1;Creating the Navigation View Component;269
5.9.1.3.2;Generating Category Lists;270
5.9.1.3.3;Creating the View;272
5.9.1.3.4;Highlighting the Current Category;273
5.9.1.4;Correcting the Page Count;276
5.9.2;Building the Shopping Cart;280
5.9.2.1;Defining the Cart Model;280
5.9.2.2;Adding the Add to Cart Buttons;284
5.9.2.3;Enabling Sessions;286
5.9.2.4;Implementing the Cart Controller;287
5.9.2.4.1;Defining Session State Extension Methods;288
5.9.2.5;Displaying the Contents of the Cart;289
5.9.3;Summary;293
5.10;Chapter 10: SportsStore: Completing the Cart;294
5.10.1;Refining the Cart Model with a Service;294
5.10.1.1;Creating a Storage-Aware Cart Class;294
5.10.1.2;Registering the Service;295
5.10.1.3;Simplifying the Cart Controller;296
5.10.2;Completing the Cart Functionality;297
5.10.2.1;Removing Items from the Cart;297
5.10.2.2;Adding the Cart Summary Widget;299
5.10.2.2.1;Adding the Font Awesome Package;299
5.10.2.2.2;Creating the View Component Class and View;300
5.10.3;Submitting Orders;302
5.10.3.1;Creating the Model Class;302
5.10.3.2;Adding the Checkout Process;303
5.10.3.3;Implementing Order Processing;307
5.10.3.3.1;Extending the Database;307
5.10.3.3.2;Creating the Order Repository;308
5.10.3.4;Completing the Order Controller;310
5.10.3.5;Displaying Validation Errors;313
5.10.3.6;Displaying a Summary Page;315
5.10.4;Summary;316
5.11;Chapter 11: SportsStore: Administration;317
5.11.1;Managing Orders;317
5.11.1.1;Enhancing the Model;317
5.11.1.2;Adding the Actions and View;318
5.11.2;Adding Catalog Management;321
5.11.2.1;Creating a CRUD Controller;322
5.11.2.2;Implementing the List View;324
5.11.2.3;Editing Products;325
5.11.2.3.1;Creating the Edit Action Method;326
5.11.2.3.2;Creating the Edit View;327
5.11.2.3.3;Updating the Product Repository;329
5.11.2.3.4;Handling Edit POST Requests;331
5.11.2.3.5;Displaying a Confirmation Message;333
5.11.2.3.6;Adding Model Validation;334
5.11.2.3.7;Enabling Client-Side Validation;337
5.11.2.4;Creating New Products;339
5.11.2.5;Deleting Products;340
5.11.3;Summary;344
5.12;Chapter 12: SportsStore: Security and Deployment;345
5.12.1;Securing the Administration Features;345
5.12.1.1;Creating the Identity Database;345
5.12.1.1.1;Creating the Context Class;345
5.12.1.1.2;Defining the Connection String;346
5.12.1.1.3;Configuring the Application;347
5.12.1.1.4;Creating and Applying the Database Migration;348
5.12.1.1.5;Defining the Seed Data;348
5.12.1.2;Applying a Basic Authorization Policy;350
5.12.1.3;Creating the Account Controller and Views;352
5.12.1.4;Testing the Security Policy;356
5.12.2;Deploying the Application;356
5.12.2.1;Creating the Databases;356
5.12.2.1.1;Opening Firewall Access for Configuration;357
5.12.2.1.2;Getting the Connection Strings;357
5.12.2.2;Preparing the Application;358
5.12.2.2.1;Creating the Error Controller and View;358
5.12.2.2.2;Defining the Production Database Settings;359
5.12.2.2.3;Configuring the Application;360
5.12.2.3;Applying the Database Migrations;362
5.12.2.4;Managing Database Seeding;362
5.12.2.4.1;Seeding Identity Data;363
5.12.2.4.2;Seeding the Product Data;364
5.12.2.5;Deploying the Application;366
5.12.3;Summary;370
5.13;Chapter 13: Working with Visual Studio Code;371
5.13.1;Setting Up the Development Environment;371
5.13.1.1;Installing Node.js;371
5.13.1.1.1;Installing Node.js on Windows;372
5.13.1.1.2;Installing Node.js on macOS;372
5.13.1.1.3;Installing Node.js on Linux;372
5.13.1.2;Checking the Node Installation;373
5.13.1.3;Installing Git;373
5.13.1.3.1;Installing Git on Windows or macOS;373
5.13.1.3.2;Installing Git on Linux;373
5.13.1.4;Checking the Git Installation;373
5.13.1.5;Installing Bower;374
5.13.1.6;Installing .NET Core;374
5.13.1.6.1;Installing .NET Core on Windows and macOS;374
5.13.1.6.2;Installing .NET Core on Linux;374
5.13.1.7;Checking the .NET Core Installation;375
5.13.1.8;Installing Visual Studio Code;375
5.13.1.8.1;Installing Visual Studio Code on Windows;375
5.13.1.8.2;Installing Visual Studio Code on macOS;375
5.13.1.8.3;Installing Visual Studio Code on Linux;376
5.13.1.9;Checking the Visual Studio Code Installation;376
5.13.1.10;Installing the Visual Studio Code C# Extension;377
5.13.2;Creating an ASP.NET Core Project;377
5.13.3;Preparing the Project with Visual Studio Code;378
5.13.3.1;Managing Client-Side Packages;379
5.13.3.2;Configuring the Application;381
5.13.3.3;Building and Running the Project;381
5.13.4;Re-creating the PartyInvites Application;382
5.13.4.1;Creating the Model and Repository;382
5.13.4.2;Creating the Database;386
5.13.4.2.1;Adding the Database Package;387
5.13.4.2.2;Creating and Applying the Database Migration;387
5.13.4.3;Creating the Controllers and Views;388
5.13.5;Unit Testing in Visual Studio Code;392
5.13.5.1;Creating a Unit Test;393
5.13.5.2;Running Tests;393
5.13.6;Summary;394
6;Part II: ASP.NET Core MVC 2 in Detail;395
6.1;Chapter 14: Configuring Applications;396
6.1.1;Preparing the Example Project;397
6.1.2;Configuring the Project;399
6.1.2.1;Adding Packages to the Project;400
6.1.2.2;Adding Tools Packages to the Project;402
6.1.3;Understanding the Program Class;403
6.1.3.1;Digging into the Configuration Detail;403
6.1.4;Understanding the Startup Class;407
6.1.4.1;Understanding ASP.NET Services;409
6.1.4.1.1;Understanding the Built-In MVC Services;411
6.1.4.2;Understanding ASP.NET Middleware;412
6.1.4.2.1;Creating Content-Generating Middleware;412
6.1.4.2.1.1;Using Services in Middleware;414
6.1.4.2.2;Creating Short-Circuiting Middleware;415
6.1.4.2.3;Creating Request-Editing Middleware;417
6.1.4.2.4;Creating Response-Editing Middleware;419
6.1.4.3;Understanding How the Configure Method Is Invoked;421
6.1.4.3.1;Using the Application Builder;422
6.1.4.3.2;Using the Hosting Environment;423
6.1.4.4;Adding the Remaining Middleware Components;426
6.1.4.4.1;Enabling Exception Handling;426
6.1.4.4.2;Enabling Browser Link;428
6.1.4.4.3;Enabling Static Content;429
6.1.5;Configuring the Application;430
6.1.5.1;Creating the JSON Configuration File;432
6.1.5.2;Using Configuration Data;434
6.1.5.3;Configuring Logging;436
6.1.5.3.1;Understanding the Logging Configuration Data;437
6.1.5.3.2;Creating Custom Log Messages;439
6.1.5.4;Configuring Dependency Injection;440
6.1.6;Configuring MVC Services;441
6.1.7;Dealing with Complex Configurations;443
6.1.7.1;Creating Different External Configuration Files;443
6.1.7.2;Creating Different Configuration Methods;445
6.1.7.3;Creating Different Configuration Classes;446
6.1.8;Summary;448
6.2;Chapter 15: URL Routing;449
6.2.1;Preparing the Example Project;450
6.2.1.1;Creating the Model Class;451
6.2.1.2;Creating the Example Controllers;451
6.2.1.3;Creating the View;452
6.2.2;Introducing URL Patterns;454
6.2.3;Creating and Registering a Simple Route;455
6.2.4;Defining Default Values;457
6.2.4.1;Defining Inline Default Values;458
6.2.5;Using Static URL Segments;460
6.2.6;Defining Custom Segment Variables;465
6.2.6.1;Using Custom Variables as Action Method Parameters;468
6.2.6.2;Defining Optional URL Segments;469
6.2.6.3;Defining Variable-Length Routes;471
6.2.7;Constraining Routes;473
6.2.7.1;Constraining a Route Using a Regular Expression;477
6.2.7.2;Using Type and Value Constraints;478
6.2.7.3;Combining Constraints;479
6.2.7.4;Defining a Custom Constraint;481
6.2.7.4.1;Defining an Inline Custom Constraint;482
6.2.8;Using Attribute Routing;483
6.2.8.1;Preparing for Attribute Routing;483
6.2.8.2;Applying Attribute Routing;484
6.2.8.2.1;Changing the Name of an Action Method;485
6.2.8.2.2;Creating a More Complex Route;486
6.2.8.3;Applying Route Constraints;487
6.2.9;Summary;488
6.3;Chapter 16: Advanced Routing Features;489
6.3.1;Preparing the Example Project;490
6.3.2;Generating Outgoing URLs in Views;491
6.3.2.1;Generating Outgoing Links;491
6.3.2.1.1;Targeting Other Controllers;495
6.3.2.1.2;Passing Extra Values;497
6.3.2.1.3;Generating Fully Qualified URLs;499
6.3.2.1.4;Generating a URL from a Specific Route;500
6.3.2.2;Generating URLs (and Not Links);503
6.3.2.2.1;Generating URLs in Action Methods;503
6.3.3;Customizing the Routing System;504
6.3.3.1;Changing the Routing System Configuration;504
6.3.3.2;Creating a Custom Route Class;506
6.3.3.2.1;Routing Incoming URLs;507
6.3.3.2.1.1;Applying a Custom Route Class;509
6.3.3.2.1.2;Routing to MVC Controllers;510
6.3.3.2.2;Generating Outgoing URLs;514
6.3.4;Working with Areas;517
6.3.4.1;Creating an Area;517
6.3.4.2;Creating an Area Route;518
6.3.4.3;Populating an Area;519
6.3.4.4;Generating Links to Actions in Areas;522
6.3.5;URL Schema Best Practices;523
6.3.5.1;Making Your URLs Clean and Human-Friendly;523
6.3.5.2;GET and POST: Picking the Right One;524
6.3.6;Summary;525
6.4;Chapter 17: Controllers and Actions;526
6.4.1;Preparing the Example Project;527
6.4.1.1;Preparing the Views;528
6.4.2;Understanding Controllers;530
6.4.3;Creating Controllers;531
6.4.3.1;Creating POCO Controllers;531
6.4.3.1.1;Using the MVC Controller API;532
6.4.3.2;Using the Controller Base Class;533
6.4.4;Receiving Context Data;535
6.4.4.1;Getting Data from Context Objects;535
6.4.4.1.1;Getting Context Data in a POCO Controller;537
6.4.4.2;Using Action Method Parameters;539
6.4.5;Producing a Response;541
6.4.5.1;Producing a Response Using the Context Object;541
6.4.5.2;Understanding Action Results;543
6.4.5.3;Producing an HTML Response;545
6.4.5.3.1;Understanding the Search for a View File;547
6.4.5.3.2;Passing Data from an Action Method to a View;549
6.4.5.3.2.1;Using a View Model Object;549
6.4.5.3.3;Passing Data with the View Bag;553
6.4.5.4;Performing Redirections;554
6.4.5.4.1;Redirecting to a Literal URL;555
6.4.5.4.2;Redirecting to a Routing System URL;557
6.4.5.4.3;Redirecting to an Action Method;558
6.4.5.4.4;Using the Post/Redirect/Get Pattern;559
6.4.5.4.5;Using Temp Data;560
6.4.5.5;Returning Different Types of Content;562
6.4.5.5.1;Producing a JSON Response;562
6.4.5.5.2;Using Objects to Generate Responses;563
6.4.5.6;Responding with the Contents of Files;564
6.4.5.7;Returning Errors and HTTP Codes;566
6.4.5.7.1;Sending a Specific HTTP Result Code;567
6.4.5.7.2;Sending a 404 Result Using a Convenience Class;568
6.4.5.8;Understanding the Other Action Result Classes;568
6.4.6;Summary;569
6.5;Chapter 18: Dependency Injection;570
6.5.1;Preparing the Example Project;571
6.5.1.1;Creating the Model and Repository;572
6.5.1.2;Creating the Controller and View;573
6.5.1.3;Creating the Unit Test Project;575
6.5.2;Creating Loosely Coupled Components;575
6.5.2.1;Examining Closely Coupled Components;576
6.5.2.1.1;Decoupling Components for Unit Testing;577
6.5.2.1.2;Using a Type Broker;579
6.5.3;Introducing ASP.NET Dependency Injection;583
6.5.3.1;Preparing for Dependency Injection;583
6.5.3.2;Configuring the Service Provider;584
6.5.3.3;Unit Testing a Controller with a Dependency;586
6.5.3.4;Using Dependency Chains;587
6.5.3.5;Using Dependency Injection for Concrete Types;589
6.5.4;Understanding Service Life Cycles;592
6.5.4.1;Using the Transient Life Cycle;593
6.5.4.1.1;Using a Factory Function;595
6.5.4.2;Using the Scoped Life Cycle;597
6.5.4.3;Using the Singleton Life Cycle;599
6.5.5;Using Action Injection;600
6.5.6;Using the Property Injection Attributes;601
6.5.7;Manually Requesting an Implementation Object;601
6.5.8;Summary;602
6.6;Chapter 19: Filters;603
6.6.1;Preparing the Example Project;604
6.6.1.1;Enabling SSL;605
6.6.1.2;Creating the Controller and View;605
6.6.2;Using Filters;607
6.6.3;Understanding Filters;610
6.6.3.1;Getting Context Data;611
6.6.4;Using Authorization Filters;612
6.6.4.1;Creating an Authorization Filter;612
6.6.5;Using Action Filters;615
6.6.5.1;Creating an Action Filter;616
6.6.5.2;Creating an Asynchronous Action Filter;618
6.6.6;Using Result Filters;619
6.6.6.1;Creating a Result Filter;620
6.6.6.2;Creating an Asynchronous Result Filter;622
6.6.6.3;Creating a Hybrid Action/Result Filter;623
6.6.7;Using Exception Filters;625
6.6.7.1;Creating an Exception Filter;626
6.6.8;Using Dependency Injection for Filters;628
6.6.8.1;Resolving Filter Dependencies;628
6.6.8.1.1;Creating Filters with Dependencies;630
6.6.8.1.2;Applying the Filters;631
6.6.8.2;Managing Filter Life Cycles;633
6.6.8.2.1;Applying the Filter;634
6.6.9;Creating Global Filters;636
6.6.10;Understanding and Changing Filter Order;638
6.6.10.1;Changing Filter Order;640
6.6.11;Summary;641
6.7;Chapter 20: API Controllers;642
6.7.1;Preparing the Example Project;643
6.7.1.1;Creating the Model and Repository;643
6.7.1.2;Creating the Controller and Views;645
6.7.1.2.1;Setting the HTTP Port;648
6.7.2;Understanding the Role of RESTful Controllers;649
6.7.2.1;Understanding the Speed Problem;649
6.7.2.2;Understanding the Efficiency Problem;649
6.7.2.3;Understanding the Openness Problem;650
6.7.3;Introducing REST and API Controllers;650
6.7.3.1;Creating an API Controller;651
6.7.3.1.1;Defining the Route;653
6.7.3.1.2;Declaring Dependencies;653
6.7.3.1.3;Defining the Action Methods;654
6.7.3.1.4;Defining the Action Results;655
6.7.3.2;Testing an API Controller;656
6.7.3.2.1;Testing the GET Operations;656
6.7.3.2.2;Testing the POST Operation;658
6.7.3.2.3;Testing the PUT Operation;658
6.7.3.2.4;Testing the Patch Operation;659
6.7.3.2.5;Testing the Delete Operation;660
6.7.3.3;Using the API Controller in the Browser;660
6.7.4;Understanding Content Formatting;662
6.7.4.1;Understanding the Default Content Policy;663
6.7.4.2;Understanding Content Negotiation;664
6.7.4.2.1;Enabling XML Formatting;665
6.7.4.3;Specifying an Action Data Format;667
6.7.4.4;Getting the Data Format from the Route or Query String;668
6.7.4.5;Enabling Full Content Negotiation;670
6.7.4.6;Receiving Different Data Formats;671
6.7.5;Summary;672
6.8;Chapter 21: Views;673
6.8.1;Preparing the Example Project;674
6.8.2;Creating a Custom View Engine;675
6.8.2.1;Creating a Custom IView;677
6.8.2.2;Creating an IViewEngine Implementation;678
6.8.2.3;Registering a Custom View Engine;679
6.8.2.4;Testing the View Engine;680
6.8.3;Working with the Razor Engine;682
6.8.3.1;Preparing the Example Project;683
6.8.3.2;Demystifying Razor Views;685
6.8.3.2.1;Understanding the Class Name;686
6.8.3.2.2;Understanding the Base Class;686
6.8.3.2.3;Understanding the View Rendering;688
6.8.4;Adding Dynamic Content to a Razor View;689
6.8.4.1;Using Layout Sections;689
6.8.4.1.1;Testing for Sections;693
6.8.4.1.2;Rendering Optional Sections;693
6.8.4.2;Using Partial Views;695
6.8.4.2.1;Creating a Partial View;695
6.8.4.2.2;Applying a Partial View;695
6.8.4.2.3;Using Strongly Typed Partial Views;697
6.8.4.3;Adding JSON Content to Views;698
6.8.5;Configuring Razor;700
6.8.5.1;Understanding View Location Expanders;701
6.8.5.1.1;Creating a Simple View Location Expander;702
6.8.5.1.1.1;Applying the View Location Expander;702
6.8.5.1.2;Selecting Specific Views for Requests;703
6.8.6;Summary;706
6.9;Chapter 22: View Components;707
6.9.1;Preparing the Example Project;708
6.9.1.1;Creating the Models and Repositories;708
6.9.1.2;Creating the Controller and Views;710
6.9.1.3;Configuring the Application;713
6.9.2;Understanding View Components;714
6.9.3;Creating a View Component;714
6.9.3.1;Creating POCO View Components;715
6.9.3.2;Deriving from the ViewComponent Base Class;716
6.9.3.3;Understanding View Component Results;718
6.9.3.3.1;Returning a Partial View;719
6.9.3.3.2;Returning HTML Fragments;721
6.9.3.4;Getting Context Data;723
6.9.3.4.1;Providing Context from the Parent View Using Arguments;726
6.9.3.5;Creating Asynchronous View Components;729
6.9.4;Creating Hybrid Controller/View Component Classes;731
6.9.4.1;Creating the Hybrid Views;732
6.9.4.2;Applying the Hybrid Class;733
6.9.5;Summary;735
6.10;Chapter 23: Understanding Tag Helpers;736
6.10.1;Preparing the Example Project;737
6.10.1.1;Creating the Model and Repository;737
6.10.1.2;Creating the Controller, Layout, and Views;738
6.10.1.3;Configuring the Application;741
6.10.2;Creating a Tag Helper;742
6.10.2.1;Defining the Tag Helper Class;743
6.10.2.1.1;Receiving Context Data;744
6.10.2.1.2;Producing Output;745
6.10.2.2;Registering Tag Helpers;746
6.10.2.3;Using a Tag Helper;747
6.10.2.4;Managing the Scope of a Tag Helper;749
6.10.2.4.1;Narrowing the Scope of a Tag Helper;750
6.10.2.4.2;Widening the Scope of a Tag Helper;751
6.10.3;Advanced Tag Helper Features;754
6.10.3.1;Creating Shorthand Elements;754
6.10.3.2;Prepending and Appending Content and Elements;756
6.10.3.2.1;Inserting Content Around the Output Element;757
6.10.3.2.2;Inserting Content Inside the Output Element;759
6.10.3.3;Getting View Context Data and Using Dependency Injection;760
6.10.3.4;Working with the View Model;762
6.10.3.5;Coordinating Between Tag Helpers;765
6.10.3.6;Suppressing the Output Element;767
6.10.4;Summary;768
6.11;Chapter 24: Using the Form Tag Helpers;769
6.11.1;Preparing the Example Project;770
6.11.1.1;Resetting the Views and Layout;770
6.11.2;Working with Form Elements;772
6.11.2.1;Setting the Form Target;773
6.11.2.2;Using the Anti-forgery Feature;774
6.11.3;Working with Input Elements;776
6.11.3.1;Configuring Input Elements;777
6.11.3.2;Formatting Data Values;779
6.11.3.2.1;Applying Formatting via the Model Class;781
6.11.4;Working with Label Elements;782
6.11.5;Working with Select and Option Elements;784
6.11.5.1;Using a Data Source to Populate a select Element;786
6.11.5.2;Generating Option Elements from an enum;786
6.11.5.2.1;Generating Option Elements from the Model;788
6.11.5.2.2;Using a Custom Tag Helper to Generate Option Elements from the Model;789
6.11.6;Working with Text Areas;791
6.11.7;Understanding the Validation Form Tag Helpers;793
6.11.8;Summary;793
6.12;Chapter 25: Using the Other Built-in Tag Helpers;794
6.12.1;Preparing the Example Project;795
6.12.2;Using the Hosting Environment Tag Helper;796
6.12.3;Using the JavaScript and CSS Tag Helpers;797
6.12.3.1;Managing JavaScript Files;797
6.12.3.1.1;Selecting JavaScript Files;798
6.12.3.1.2;Narrowing the Globbing Pattern;801
6.12.3.1.2.1;Excluding Files;802
6.12.3.1.2.2;Using the Hosting Environment to Select Files;803
6.12.3.1.3;Working with Content Delivery Networks;805
6.12.3.2;Managing CSS Stylesheets;807
6.12.3.2.1;Selecting Stylesheets;808
6.12.3.2.2;Working with Content Delivery Networks;809
6.12.4;Working with Anchor Elements;810
6.12.5;Working with Image Elements;811
6.12.6;Using the Data Cache;812
6.12.6.1;Setting Cache Expiry;815
6.12.6.1.1;Setting a Fixed Expiry Point;816
6.12.6.1.2;Setting a Last-Used Expiry Period;817
6.12.6.2;Using Cache Variations;817
6.12.7;Using Application-Relative URLs;819
6.12.8;Summary;822
6.13;Chapter 26: Model Binding;823
6.13.1;Preparing the Example Project;824
6.13.1.1;Creating the Model and Repository;824
6.13.1.2;Creating the Controller and View;826
6.13.1.3;Configuring the Application;827
6.13.2;Understanding Model Binding;829
6.13.2.1;Understanding Default Binding Values;830
6.13.2.2;Binding Simple Types;832
6.13.2.3;Binding Complex Types;833
6.13.2.3.1;Creating Easily Bound HTML;835
6.13.2.3.2;Specifying Custom Prefixes;838
6.13.2.3.3;Selectively Binding Properties;842
6.13.2.4;Binding to Arrays and Collections;844
6.13.2.4.1;Binding to Arrays;844
6.13.2.4.2;Binding to Collections;846
6.13.2.4.3;Binding to Collections of Complex Types;848
6.13.3;Specifying a Model Binding Source;851
6.13.3.1;Selecting a Standard Binding Source;852
6.13.3.2;Using Headers As Binding Sources;853
6.13.3.2.1;Binding Complex Types from Headers;855
6.13.3.3;Using Request Bodies as Binding Sources;857
6.13.4;Summary;859
6.14;Chapter 27: Model Validation;860
6.14.1;Preparing the Example Project;861
6.14.1.1;Creating the Model;862
6.14.1.2;Creating the Controller;862
6.14.1.3;Creating the Layout and Views;863
6.14.2;Understanding the Need for Model Validation;866
6.14.3;Explicitly Validating a Model;866
6.14.3.1;Displaying Validation Errors to the User;869
6.14.3.2;Displaying Validation Messages;871
6.14.3.2.1;Configuring the Default Validation Error Messages;873
6.14.3.3;Displaying Property-Level Validation Messages;875
6.14.3.4;Displaying Model-Level Messages;877
6.14.4;Specifying Validation Rules Using Metadata;880
6.14.4.1;Creating a Custom Property Validation Attribute;883
6.14.5;Performing Client-Side Validation;885
6.14.6;Performing Remote Validation;888
6.14.7;Summary;891
6.15;Chapter 28: Getting Started with Identity;892
6.15.1;Preparing the Example Project;893
6.15.1.1;Creating the Controller and View;894
6.15.2;Setting Up ASP.NET Core Identity;896
6.15.2.1;Creating the User Class;896
6.15.2.1.1;Configuring the View Imports;897
6.15.2.2;Creating the Database Context Class;898
6.15.2.3;Configuring the Database Connection String Setting;898
6.15.2.4;Creating the Identity Database;901
6.15.3;Using ASP.NET Core Identity;901
6.15.3.1;Enumerating User Accounts;901
6.15.3.2;Creating Users;904
6.15.3.2.1;Testing the Create Functionality;906
6.15.3.3;Validating Passwords;908
6.15.3.3.1;Implementing a Custom Password Validator;910
6.15.3.4;Validating User Details;915
6.15.3.4.1;Implementing Custom User Validation;918
6.15.4;Completing the Administration Features;921
6.15.4.1;Implementing the Delete Feature;921
6.15.4.2;Implementing the Edit Feature;923
6.15.4.2.1;Creating the View;926
6.15.5;Summary;928
6.16;Chapter 29: Applying ASP.NET Core Identity;929
6.16.1;Preparing the Example Project;929
6.16.2;Authenticating Users;930
6.16.2.1;Preparing to Implement Authentication;932
6.16.2.2;Adding User Authentication;935
6.16.2.3;Testing Authentication;937
6.16.3;Authorizing Users with Roles;938
6.16.3.1;Creating and Deleting Roles;939
6.16.3.1.1;Creating the Views;941
6.16.3.1.2;Testing, Creating, and Deleting Roles;944
6.16.3.2;Managing Role Memberships;944
6.16.3.2.1;Testing and Editing Role Membership;948
6.16.3.3;Using Roles for Authorization;950
6.16.4;Seeding the Database;953
6.16.5;Summary;957
6.17;Chapter 30: Advanced ASP.NET Core Identity;958
6.17.1;Preparing the Example Project;958
6.17.2;Adding Custom User Properties;960
6.17.2.1;Preparing for Database Migration;963
6.17.2.2;Testing the Custom Properties;964
6.17.3;Working with Claims and Policies;964
6.17.3.1;Understanding Claims;965
6.17.3.2;Creating Claims;969
6.17.3.3;Using Policies;973
6.17.3.3.1;Creating Custom Policy Requirements;976
6.17.3.4;Using Policies to Authorize Access to Resources;979
6.17.3.4.1;Creating the Resource Authorization Policy and Handler;981
6.17.4;Using Third-Party Authentication;985
6.17.4.1;Registering the Application with Google;985
6.17.4.2;Enabling Google Authentication;985
6.17.5;Summary;990
6.18;Chapter 31: Model Conventions and Action Constraints;991
6.18.1;Preparing the Example Project;991
6.18.1.1;Creating the View Model, Controller, and View;992
6.18.2;Using the Application Model and Model Conventions;994
6.18.2.1;Understanding the Application Model;995
6.18.2.1.1;Customizing the Application Model;997
6.18.2.2;Understanding the Role of Model Conventions;999
6.18.2.3;Creating a Model Convention;1000
6.18.2.3.1;Using Conventions That Add or Remove Models;1001
6.18.2.4;Understanding Model Convention Execution Order;1005
6.18.2.5;Creating Global Model Conventions;1006
6.18.3;Using Action Constraints;1008
6.18.3.1;Preparing the Example Project;1008
6.18.3.2;Understanding Action Constraints;1011
6.18.3.3;Creating an Action Constraint;1012
6.18.3.3.1;Creating a Comparative Action Constraint;1014
6.18.3.4;Resolving Dependencies in Action Constraints;1016
6.18.4;Summary;1019
7;Index;1020



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.