Pro ASP.NET Core 7, Tenth Edition

Book description

Now in its tenth edition, this industry-leading guide to ASP.NET Core teaches everything you need to know to create easy, extensible, and cloud-native web applications.

Inside Pro ASP.NET Core 7 you will learn how to:

  • Configure the ASP.NET Core request pipeline to handle requests
  • Create RESTful web services with MVC controllers
  • Create HTML responses with Razor and Razor Pages
  • Create richly interactive web applications with Blazor
  • Access data using Entity Framework Core
  • Authenticate requests using ASP.NET Core Identity

Pro ASP.NET Core is an acclaimed bestseller, and a bible for .NET web developers. Tens of thousands of readers have benefited from its comprehensive coverage of ASP.NET’s key tools and techniques. Now in its tenth edition, this revised guide has been fully updated to .NET 7, with extensive chapters on Razor Pages, Blazor, and the MVC framework. It maintains the style and structure of popular previous editions, with content updated for ASP.NET Core’s latest evolution.

About the Technology
ASP.NET Core 7 gives you everything you need to create awesome web apps in C#. This powerful framework handles anything you throw at it, from high-volume HTTP requests and RESTful web services, to efficient HTML and CSS round trips and WebAssembly for rich user interactions.

About the Book
Pro ASP.NET Core 7 is the industry-leading guide to building web applications with ASP.NET Core. In it, you’ll build a realistic online store as you learn about web services, authentication and authorization, container deployment, and more. Author Adam Freeman’s comfortable style mentors you through advanced topics like RESTful web services, Razor Pages for HTML responses, and data access with Entity Framework Core. Engaging hands-on examples show you how each tool works in action.

What's Inside
  • The ASP.NET Core request pipeline
  • RESTful web services with MVC controllers
  • Rich interactive applications with Blazor
  • Authenticate requests using ASP.NET Core Identity


About the Reader
For web developers experienced with C# and the basics of .NET.

About the Author
Adam Freeman has written over a dozen bestselling books on software development. He has held numerous senior IT positions, most recently as CTO and COO of a global bank. The technical editor on this book is Fabio Claudio Ferracchiati.

Quotes
A masterpiece that exceeds all expectations. My ultimate guide for the world of ASP.NET Core.
- Juan Luis Barreda, Senior Software Developer, Pearson.com

Go from scratch all the way into ASP.NET Core. The complete guide.
- Ernesto Cardenas Cangahuala, Microsoft MVP and Technical Architect at Interbank

This tome has been helping developers learn ASP.NET for years and this edition builds upon that success.
- Jeffrey Smith, IT Engineering Manager, TJ Maxx

A complete tour of the ASP.NET Core framework.
- David Paccoud, Solution Architect, Clario

If you’re looking for breadth and depth coverage of ASP.NET Core development, this is the book for you.
- Greg White, Software Development Manager, PicoBrew Inc.

A must have book for the .NET developer/engineer.
- Foster Haines, Consultant, Foster’s Website Company

The book for web development professionals.
- Renato Gentile, Solutions Architect, S3K S.p.A.

This book guides you as a beginner and will remain your for-ever reference book.
- Werner Nindl, Partner, Nova Advisory

An encyclopedic journey.
- Richard Young, IT Director, Design Synthesis, Inc

From tiny throw-away sites to large production websites, this book teaches all you need to know.
- Samuel Bosch, Team Lead, ILVO

By the end of this book you should be able to write code for real-world projects.
- Rich Yonts, Senior Software Engineer, Teradata

Table of contents

  1. Praises from reviewers of Pro ASP.NET Core 7, Tenth Edition
  2. Pro ASP.NET Core 7
  3. Copyright
  4. dedication
  5. contents
  6. front matter
    1. preface
    2. about this book
      1. Who should read this book
      2. How this book is organized: a roadmap
      3. About the code
      4. liveBook discussion forum
    3. about the author
    4. about the cover illustration
  7. 1 Putting ASP.NET Core in context
    1. 1.1 Understanding the application frameworks
      1. 1.1.1 Understanding the MVC Framework
      2. 1.1.2 Understanding Razor Pages
      3. 1.1.3 Understanding Blazor
      4. 1.1.4 Understanding the utility frameworks
      5. 1.1.5 Understanding the ASP.NET Core platform
    2. 1.2 Understanding this book
      1. 1.2.1 What software do I need to follow the examples?
      2. 1.2.2 What platform do I need to follow the examples?
      3. 1.2.3 What if I have problems following the examples?
      4. 1.2.4 What if I find an error in the book?
      5. 1.2.5 What does this book cover?
      6. 1.2.6 What doesn’t this book cover?
      7. 1.2.7 How do I contact the author?
      8. 1.2.8 What if I really enjoyed this book?
      9. 1.2.9 What if this book has made me angry and I want to complain?
    3. Summary
  8. Part 1.
  9. 2 Getting started
    1. 2.1 Choosing a code editor
      1. 2.1.1 Installing Visual Studio
      2. 2.1.3 Installing Visual Studio Code
    2. 2.2 Creating an ASP.NET Core project
      1. 2.2.1 Opening the project using Visual Studio
      2. 2.2.2 Opening the project with Visual Studio Code
    3. 2.3 Running the ASP.NET Core application
      1. 2.3.1 Understanding endpoints
      2. 2.3.2 Understanding routes
      3. 2.3.3 Understanding HTML rendering
      4. 2.3.4 Putting the pieces together
    4. Summary
  10. 3 Your first ASP.NET Core application
    1. 3.1 Setting the scene
    2. 3.2 Creating the project
      1. 3.2.1 Preparing the project
      2. 3.2.2 Adding a data model
      3. 3.2.3 Creating a second action and view
      4. 3.2.4 Linking action methods
      5. 3.2.5 Building the form
      6. 3.2.6 Receiving form data
      7. 3.2.7 Adding the Thanks view
      8. 3.2.8 Displaying responses
      9. 3.2.9 Adding validation
      10. 3.2.10 Styling the content
    3. Summary
  11. 4 Using the development tools
    1. 4.1 Creating ASP.NET Core projects
      1. 4.1.1 Creating a project using the command line
    2. 4.2 Adding code and content to projects
      1. 4.2.1 Understanding item scaffolding
    3. 4.3 Building and running projects
      1. 4.3.1 Using the hot reload feature
    4. 4.4 Managing packages
      1. 4.4.1 Managing NuGet packages
      2. 4.4.2 Managing tool packages
      3. 4.4.3 Managing client-side packages
    5. 4.5 Debugging projects
    6. Summary
  12. 5 Essential C# features
    1. 5.1 Preparing for this chapter
      1. 5.1.1 Opening the project
      2. 5.1.2 Enabling the MVC Framework
      3. 5.1.3 Creating the application components
      4. 5.1.4 Selecting the HTTP port
      5. 5.1.5 Running the example application
    2. 5.2 Understanding top-level statements
    3. 5.3 Understanding global using statements
      1. 5.3.1 Understanding implicit using statements
    4. 5.4 Understanding null state analysis
      1. 5.4.1 Ensuring fields and properties are assigned values
      2. 5.4.2 Providing a default value for non-nullable types
      3. 5.4.3 Using nullable types
      4. 5.4.4 Checking for null values
      5. 5.4.5 Overriding null state analysis
      6. 5.4.6 Disabling null state analysis warnings
    5. 5.5 Using string interpolation
    6. 5.6 Using object and collection initializers
      1. 5.6.1 Using an index initializer
    7. 5.7 Using target-typed new expressions
    8. 5.8 Pattern Matching
      1. 5.8.1 Pattern matching in switch statements
    9. 5.9 Using extension methods
      1. 5.9.1 Applying extension methods to an interface
      2. 5.9.2 Creating filtering extension methods
    10. 5.10 Using lambda expressions
      1. 5.10.1 Defining functions
      2. 5.10.2 Using lambda expression methods and properties
    11. 5.11 Using type inference and anonymous types
      1. 5.11.1 Using anonymous types
    12. 5.12 Using default implementations in interfaces
    13. 5.13 Using asynchronous methods
      1. 5.13.1 Working with tasks directly
      2. 5.13.2 Applying the async and await keywords
      3. 5.13.3 Using an asynchronous enumerable
    14. 5.14 Getting names
    15. Summary
  13. 6 Testing ASP.NET Core applications
    1. 6.1 Preparing for this chapter
      1. 6.1.1 Opening the project
      2. 6.1.2 Selecting the HTTP port
      3. 6.1.3 Enabling the MVC Framework
      4. 6.1.4 Creating the application components
      5. 6.1.5 Running the example application
    2. 6.2 Creating a unit test project
    3. 6.3 Writing and running unit tests
      1. 6.3.1 Running tests with the Visual Studio Test Explorer
      2. 6.3.2 Running tests with Visual Studio Code
      3. 6.3.3 Running tests from the command line
      4. 6.3.4 Correcting the unit test
      5. 6.3.5 Isolating components for unit testing
      6. 6.3.6 Using a mocking package
      7. 6.3.7 Creating a mock object
    4. Summary
  14. 7 SportsStore: A real application
    1. 7.1 Creating the projects
      1. 7.1.1 Creating the unit test project
      2. 7.1.2 Opening the projects
      3. 7.1.3 Configuring the HTTP port
      4. 7.1.4 Creating the application project folders
      5. 7.1.5 Preparing the services and the request pipeline
      6. 7.1.6 Configuring the Razor view engine
      7. 7.1.7 Creating the controller and view
      8. 7.1.8 Starting the data model
      9. 7.1.9 Checking and running the application
    2. 7.2 Adding data to the application
      1. 7.2.1 Installing the Entity Framework Core packages
      2. 7.2.2 Defining the connection string
      3. 7.2.3 Creating the database context class
      4. 7.2.4 Configuring Entity Framework Core
      5. 7.2.5 Creating a repository
      6. 7.2.6 Creating the database migration
      7. 7.2.7 Creating seed data
    3. 7.3 Displaying a list of products
      1. 7.3.1 Preparing the controller
      2. 7.3.2 Updating the view
      3. 7.3.3 Running the application
    4. 7.4 Adding pagination
      1. 7.4.1 Displaying page links
      2. 7.4.2 Improving the URLs
    5. 7.5 Styling the content
      1. 7.5.1 Installing the Bootstrap package
      2. 7.5.2 Applying Bootstrap styles
      3. 7.5.3 Creating a partial view
    6. Summary
  15. 8 SportsStore: Navigation and cart
    1. 8.1 Adding navigation controls
      1. 8.1.1 Filtering the product list
      2. 8.1.2 Refining the URL scheme
      3. 8.1.3 Building a category navigation menu
      4. 8.1.4 Correcting the page count
    2. 8.2 Building the shopping cart
      1. 8.2.1 Configuring Razor Pages
      2. 8.2.2 Creating a Razor Page
      3. 8.2.3 Creating the Add to Cart buttons
      4. 8.2.4 Enabling sessions
      5. 8.2.5 Implementing the cart feature
    3. Summary
  16. 9 SportsStore: Completing the cart
    1. 9.1 Refining the cart model with a service
      1. 9.1.1 Creating a storage-aware cart class
      2. 9.1.2 Registering the service
      3. 9.1.3 Simplifying the cart Razor Page
    2. 9.2 Completing the cart functionality
      1. 9.2.1 Removing items from the cart
      2. 9.2.2 Adding the cart summary widget
    3. 9.3 Submitting orders
      1. 9.3.1 Creating the model class
      2. 9.3.2 Adding the checkout process
      3. 9.3.3 Creating the controller and view
      4. 9.3.4 Implementing order processing
      5. 9.3.5 Completing the order controller
      6. 9.3.6 Displaying validation errors
      7. 9.3.7 Displaying a summary page
    4. Summary
  17. 10 SportsStore: Administration
    1. 10.1 Preparing Blazor Server
      1. 10.1.1 Creating the imports file
      2. 10.1.2 Creating the startup Razor Page
      3. 10.1.3 Creating the routing and layout components
      4. 10.1.4 Creating the Razor Components
      5. 10.1.5 Checking the Blazor setup
    2. 10.2 Managing orders
      1. 10.2.1 Enhancing the model
      2. 10.2.2 Displaying orders to the administrator
    3. 10.3 Adding catalog management
      1. 10.3.1 Expanding the repository
      2. 10.3.2 Applying validation attributes to the data model
      3. 10.3.3 Creating the list component
      4. 10.3.4 Creating the detail component
      5. 10.3.5 Creating the editor component
      6. 10.3.6 Deleting products
    4. Summary
  18. 11 SportsStore: Security and deployment
    1. 11.1 Creating the Identity database
      1. 11.1.1 Installing the Identity package for Entity Framework Core
      2. 11.1.2 Creating the context class
      3. 11.1.3 Defining the connection string
      4. 11.1.4 Configuring the application
      5. 11.1.5 Creating and applying the database migration
      6. 11.1.6 Defining the seed data
    2. 11.2 Adding a conventional administration feature
    3. 11.3 Applying a basic authorization policy
    4. 11.4 Creating the account controller and views
    5. 11.5 Testing the security policy
    6. 11.6 Preparing ASP.NET Core for deployment
      1. 11.6.1 Configuring error handling
      2. 11.6.2 Creating the production configuration settings
      3. 11.6.3 Creating the Docker image
      4. 11.6.4 Running the containerized application
    7. Summary
  19. Part 2.
  20. 12 Understanding the ASP.NET Core platform
    1. 12.1 Preparing for this chapter
      1. 12.1.1 Running the example application
    2. 12.2 Understanding the ASP.NET Core platform
      1. 12.2.1 Understanding middleware and the request pipeline
      2. 12.2.2 Understanding services
    3. 12.3 Understanding the ASP.NET Core project
      1. 12.3.1 Understanding the entry point
      2. 12.3.2 Understanding the project file
    4. 12.4 Creating custom middleware
      1. 12.4.1 Defining middleware using a class
      2. 12.4.2 Understanding the return pipeline path
      3. 12.4.3 Short-Circuiting the request pipeline
      4. 12.4.4 Creating pipeline branches
      5. 12.4.5 Creating terminal middleware
    5. 12.5 Configuring middleware
      1. 12.5.1 Using the options pattern with class-based middleware
    6. Summary
  21. 13 Using URL routing
    1. 13.1 Preparing for this chapter
      1. 13.1.1 Understanding URL routing
      2. 13.1.2 Adding the routing middleware and defining an endpoint
      3. 13.1.3 Simplifying the pipeline configuration
      4. 13.1.4 Understanding URL patterns
      5. 13.1.5 Using segment variables in URL patterns
      6. 13.1.6 Generating URLs from routes
    2. 13.2 Managing URL matching
      1. 13.2.1 Matching multiple values from a single URL segment
      2. 13.2.2 Using default values for segment variables
      3. 13.2.3 Using optional segments in a URL Pattern
      4. 13.2.4 Using a catchall segment variable
      5. 13.2.5 Constraining segment matching
      6. 13.2.6 Defining fallback routes
    3. 13.3 Advanced routing features
      1. 13.3.1 Creating custom constraints
      2. 13.3.2 Avoiding ambiguous route exceptions
      3. 13.3.3 Accessing the endpoint in a middleware component
    4. Summary
  22. 14 Using dependency injection
    1. 14.1 Preparing for this chapter
      1. 14.1.1 Creating a middleware component and an endpoint
      2. 14.1.2 Configuring the request pipeline
    2. 14.2 Understanding service location and tight coupling
      1. 14.2.1 Understanding the service location problem
      2. 14.2.2 Understanding the tightly coupled components problem
    3. 14.3 Using dependency injection
      1. 14.3.1 Using a Service with a Constructor Dependency
      2. 14.3.2 Getting services from the HttpContext object
    4. 14.4 Using Service Lifecycles
      1. 14.4.1 Creating transient services
      2. 14.4.2 Avoiding the transient service reuse pitfall
      3. 14.4.3 Using scoped services
    5. 14.5 Other dependency injection features
      1. 14.5.1 Creating dependency chains
      2. 14.5.2 Accessing services in the Program.cs file
      3. 14.5.3 Using service factory functions
      4. 14.5.4 Creating services with multiple implementations
      5. 14.5.5 Using unbound types in services
    6. Summary
  23. 15 Using the platform features, part 1
    1. 15.1 Preparing for this chapter
    2. 15.2 Using the configuration service
      1. 15.2.1 Understanding the environment configuration file
      2. 15.2.2 Accessing configuration settings
      3. 15.2.3 Using the configuration data in the Program.cs file
      4. 15.2.4 Using configuration data with the options pattern
      5. 15.2.5 Understanding the launch settings file
      6. 15.2.6 Using the environment service
      7. 15.2.7 Storing user secrets
    3. 15.3 Using the logging service
      1. 15.3.1 Generating logging messages
      2. 15.3.2 Logging messages with attributes
      3. 15.3.3 Configuring minimum logging levels
      4. 15.3.4 Logging HTTP requests and responses
    4. 15.4 Using static content and client-side packages
      1. 15.4.1 Adding the static content middleware
      2. 15.4.2 Using client-side packages
    5. Summary
  24. 16 Using the platform features, part 2
    1. 16.1 Preparing for this chapter
    2. 16.2 Using cookies
      1. 16.2.1 Enabling cookie consent checking
      2. 16.2.2 Managing cookie consent
    3. 16.3 Using sessions
      1. 16.3.1 Configuring the session service and middleware
      2. 16.3.2 Using session data
    4. 16.4 Working with HTTPS connections
      1. 16.4.1 Enabling HTTPS connections
      2. 16.4.2 Detecting HTTPS requests
      3. 16.4.3 Enforcing HTTPS requests
      4. 16.4.4 Enabling HTTP strict transport security
    5. 16.5 Using rate limits
    6. 16.6 Handling exceptions and errors
      1. 16.6.1 Returning an HTML error response
      2. 16.6.2 Enriching status code responses
    7. 16.7 Filtering requests using the host header
    8. Summary
  25. 17 Working with data
    1. 17.1 Preparing for this chapter
    2. 17.2 Caching data
      1. 17.2.1 Caching data values
      2. 17.2.2 Using a shared and persistent data cache
    3. 17.3 Caching responses
    4. 17.4 Caching output
      1. 17.4.1 Defining a custom cache policy
    5. 17.5 Using Entity Framework Core
      1. 17.5.1 Installing Entity Framework Core
      2. 17.5.2 Creating the data model
      3. 17.5.3 Configuring the database service
      4. 17.5.4 Creating and applying the database migration
      5. 17.5.5 Seeding the database
      6. 17.5.6 Using data in an endpoint
    6. Summary
  26. Part 3.
  27. 18 Creating the example project
    1. 18.1 Creating the project
    2. 18.2 Adding a data model
      1. 18.2.1 Adding NuGet packages to the project
      2. 18.2.2 Creating the data model
      3. 18.2.3 Preparing the seed data
      4. 18.2.4 Configuring EF Core services and middleware
      5. 18.2.5 Creating and applying the migration
    3. 18.3 Adding the CSS framework
    4. 18.4 Configuring the request pipeline
    5. 18.5 Running the example application
  28. 19 Creating RESTful web services
    1. 19.1 Preparing for this chapter
    2. 19.2 Understanding RESTful web services
      1. 19.2.1 Understanding request URLs and methods
      2. 19.2.2 Understanding JSON
    3. 19.3 Creating a web service using the minimal API
    4. 19.4 Creating a web service using a controller
      1. 19.4.1 Enabling the MVC Framework
      2. 19.4.2 Creating a controller
    5. 19.5 Improving the web service
      1. 19.5.1 Using asynchronous actions
      2. 19.5.2 Preventing over-binding
      3. 19.5.3 Using action results
      4. 19.5.4 Validating data
      5. 19.5.5 Applying the API controller attribute
      6. 19.5.6 Omitting Null properties
      7. 19.5.7 Applying a rate limit
    6. Summary
  29. 20 Advanced web service features
    1. 20.1 Preparing for this chapter
      1. 20.1.1 Dropping the database
      2. 20.1.2 Running the example application
    2. 20.2 Dealing with related data
      1. 20.2.1 Breaking circular references in related data
    3. 20.3 Supporting the HTTP PATCH method
      1. 20.3.1 Understanding JSON Patch
      2. 20.3.2 Installing and configuring the JSON Patch package
      3. 20.3.3 Defining the action method
    4. 20.4 Understanding content formatting
      1. 20.4.1 Understanding the default content policy
      2. 20.4.2 Understanding content negotiation
      3. 20.4.3 Specifying an action result format
      4. 20.4.4 Requesting a format in the URL
      5. 20.4.5 Restricting the formats received by an action method
      6. 20.4.6 Caching output
    5. 20.5 Documenting and exploring web services
      1. 20.5.1 Resolving action conflicts
      2. 20.5.2 Installing and configuring the Swashbuckle package
      3. 20.5.3 Fine-Tuning the API description
    6. Summary
  30. 21 Using controllers with views, part I
    1. 21.1 Preparing for this chapter
      1. 21.1.1 Dropping the database
      2. 21.1.2 Running the example application
    2. 21.2 Getting started with views
      1. 21.2.1 Configuring the application
      2. 21.2.2 Creating an HTML controller
      3. 21.2.3 Creating a Razor View
      4. 21.2.4 Selecting a View by name
    3. 21.3 Working with Razor Views
      1. 21.3.1 Setting the view model type
      2. 21.3.2 Understanding the view model type pitfall
    4. 21.4 Understanding the Razor syntax
      1. 21.4.1 Understanding directives
      2. 21.4.2 Understanding content expressions
      3. 21.4.3 Setting element content
      4. 21.4.4 Setting attribute values
      5. 21.4.5 Using conditional expressions
      6. 21.4.6 Enumerating sequences
      7. 21.4.7 Using Razor code blocks
    5. Summary
  31. 22 Using controllers with views, part II
    1. 22.1 Preparing for this chapter
      1. 22.1.1 Dropping the database
      2. 22.1.2 Running the example application
    2. 22.2 Using the view bag
    3. 22.3 Using temp data
    4. 22.4 Working with layouts
      1. 22.4.1 Configuring layouts using the view bag
      2. 22.4.2 Using a view start file
      3. 22.4.3 Overriding the default layout
      4. 22.4.4 Using layout sections
    5. 22.5 Using partial views
      1. 22.5.1 Enabling partial views
      2. 22.5.2 Creating a partial view
      3. 22.5.3 Applying a partial view
    6. 22.6 Understanding content-encoding
      1. 22.6.1 Understanding HTML encoding
      2. 22.6.2 Understanding JSON encoding
    7. Summary
  32. 23 Using Razor Pages
    1. 23.1 Preparing for this chapter
      1. 23.1.1 Running the example application
    2. 23.2 Understanding Razor Pages
      1. 23.2.1 Configuring Razor Pages
      2. 23.2.2 Creating a Razor Page
    3. 23.3 Understanding Razor Pages routing
      1. 23.3.1 Specifying a routing pattern in a Razor Page
      2. 23.3.2 Adding routes for a Razor Page
    4. 23.4 Understanding the Page model class
      1. 23.4.1 Using a code-behind class file
      2. 23.4.2 Understanding action results in Razor Pages
      3. 23.4.3 Handling multiple HTTP methods
      4. 23.4.4 Selecting a handler method
    5. 23.5 Understanding the Razor Page view
      1. 23.5.1 Creating a layout for Razor Pages
      2. 23.5.2 Using partial views in Razor Pages
      3. 23.5.3 Creating Razor Pages without page models
    6. Summary
  33. 24 Using view components
    1. 24.1 Preparing for this chapter
      1. 24.1.1 Dropping the database
      2. 24.1.2 Running the example application
    2. 24.2 Understanding view components
    3. 24.3 Creating and using a view component
      1. 24.3.1 Applying a view component
    4. 24.4 Understanding view component results
      1. 24.4.1 Returning a partial view
      2. 24.4.2 Returning HTML fragments
    5. 24.5 Getting context data
      1. 24.5.1 Providing context from the parent view using arguments
      2. 24.5.2 Creating asynchronous view components
    6. 24.6 Creating view components classes
      1. 24.6.1 Creating a hybrid controller class
    7. Summary
  34. 25 Using tag helpers
    1. 25.1 Preparing for this chapter
      1. 25.1.1 Dropping the database
      2. 25.1.2 Running the example application
    2. 25.2 Creating a tag helper
      1. 25.2.1 Defining the tag helper class
      2. 25.2.2 Registering tag helpers
      3. 25.2.3 Using a tag helper
      4. 25.2.4 Narrowing the scope of a tag helper
      5. 25.2.5 Widening the scope of a tag helper
    3. 25.3 Advanced tag helper features
      1. 25.3.1 Creating shorthand elements
      2. 25.3.2 Creating elements programmatically
      3. 25.3.3 Prepending and appending content and elements
      4. 25.3.4 Getting view context data
      5. 25.3.5 Working with model expressions
      6. 25.3.6 Coordinating between tag helpers
      7. 25.3.7 Suppressing the output element
    4. 25.4 Using tag helper components
      1. 25.4.1 Creating a tag helper component
      2. 25.4.2 Expanding tag helper component element selection
    5. Summary
  35. 26 Using the built-in tag helpers
    1. 26.1 Preparing for this chapter
      1. 26.1.1 Adding an image file
      2. 26.1.2 Installing a client-side package
      3. 26.1.3 Dropping the database
      4. 26.1.4 Running the example application
    2. 26.2 Enabling the built-in tag helpers
    3. 26.3 Transforming anchor elements
      1. 26.3.1 Using anchor elements for Razor Pages
    4. 26.4 Using the JavaScript and CSS tag helpers
      1. 26.4.1 Managing JavaScript files
      2. 26.4.2 Managing CSS stylesheets
    5. 26.5 Working with image elements
    6. 26.6 Using the data cache
      1. 26.6.1 Setting cache expiry
    7. 26.7 Using the hosting environment tag helper
    8. Summary
  36. 27 Using the forms tag helpers
    1. 27.1 Preparing for this chapter
      1. 27.1.1 Dropping the database
      2. 27.1.2 Running the example application
    2. 27.2 Understanding the form handling pattern
      1. 27.2.1 Creating a controller to handle forms
      2. 27.2.2 Creating a Razor Page to handle forms
    3. 27.3 Using tag helpers to improve HTML forms
      1. 27.3.1 Working with form elements
      2. 27.3.2 Transforming form buttons
    4. 27.4 Working with input elements
      1. 27.4.1 Transforming the input element type attribute
      2. 27.4.2 Formatting input element values
      3. 27.4.3 Displaying values from related data in input elements
    5. 27.5 Working with label elements
    6. 27.6 Working with select and option elements
      1. 26.6.1 Populating a select element
    7. 27.7 Working with text areas
    8. 27.8 Using the anti-forgery feature
      1. 27.8.1 Enabling the anti-forgery feature in a controller
      2. 27.8.2 Enabling the anti-forgery feature in a Razor Page
      3. 27.8.3 Using anti-forgery tokens with JavaScript clients
    9. Summary
  37. 28 Using model binding
    1. 28.1 Preparing for this chapter
      1. 28.1.1 Dropping the database
      2. 28.1.2 Running the example application
    2. 28.2 Understanding model binding
    3. 28.3 Binding simple data types
      1. 28.3.1 Binding simple data types in Razor Pages
      2. 28.3.2 Understanding default binding values
    4. 28.4 Binding complex types
      1. 28.4.1 Binding to a property
      2. 28.4.2 Binding nested complex types
      3. 28.4.3 Selectively binding properties
    5. 28.5 Binding to arrays and collections
      1. 28.5.1 Binding to arrays
      2. 28.5.2 Binding to simple collections
      3. 28.5.3 Binding to dictionaries
      4. 28.5.4 Binding to collections of complex types
    6. 28.6 Specifying a model binding source
      1. 28.6.1 Selecting a binding source for a property
      2. 28.6.2 Using headers for model binding
      3. 28.6.3 Using request bodies as binding sources
    7. 28.7 Manual model binding
    8. Summary
  38. 29 Using model validation
    1. 29.1 Preparing for this chapter
      1. 29.1.1 Dropping the database
      2. 29.1.2 Running the example application
    2. 29.2 Understanding the need for model validation
    3. 29.3 Validating data
      1. 29.3.1 Displaying validation messages
      2. 29.3.2 Understanding the implicit validation checks
      3. 29.3.3 Performing explicit validation
      4. 29.3.4 Configuring the default validation error messages
      5. 29.3.4 Displaying property-level validation messages
      6. 29.3.5 Displaying model-level messages
    4. 29.4 Explicitly validating data in a Razor Page
    5. 29.5 Specifying validation rules using metadata
      1. 29.5.1 Creating a custom property validation attribute
      2. 29.5.2 Creating a custom model validation attribute
    6. 29.6 Performing client-side validation
    7. 29.7 Performing remote validation
      1. 29.7.1 Performing remote validation in Razor Pages
    8. Summary
  39. 30 Using filters
    1. 30.1 Preparing for this chapter
      1. 30.1.1 Enabling HTTPS Connections
      2. 30.1.2 Dropping the database
      3. 30.1.3 Running the example application
    2. 30.2 Using filters
    3. 30.3 Understanding filters
    4. 30.4 Creating custom filters
      1. 30.4.1 Understanding authorization filters
      2. 30.4.2 Understanding resource filters
      3. 30.4.3 Understanding action filters
      4. 30.4.4 Understanding page filters
      5. 30.4.5 Understanding result filters
      6. 30.4.6 Understanding exception filters
      7. 30.4.7 Creating an exception filter
    5. 30.5 Managing the filter lifecycle
      1. 30.5.1 Creating filter factories
      2. 30.5.2 Using dependency injection scopes to manage filter lifecycles
    6. 30.6 Creating global filters
    7. 30.7 Understanding and changing filter order
    8. Summary
  40. 31 Creating form applications
    1. 31.1 Preparing for this chapter
      1. 31.1.1 Dropping the database
      2. 31.1.2 Running the example application
    2. 31.2 Creating an MVC forms application
      1. 31.2.1 Preparing the view model and the view
      2. 31.2.2 Reading data
      3. 31.2.3 Creating data
      4. 31.2.4 Editing data
      5. 31.2.5 Deleting data
    3. 31.3 Creating a Razor Pages forms application
      1. 31.3.1 Creating common functionality
      2. 31.3.2 Defining pages for the CRUD operations
    4. 31.4 Creating new related data objects
      1. 31.4.1 Providing the related data in the same request
      2. 31.4.2 Breaking out to create new data
    5. Summary
  41. Part 4.
  42. 32 Creating the example project
    1. 32.1 Creating the project
      1. 32.1.1 Adding NuGet packages to the project
    2. 32.2 Adding a data model
      1. 32.2.1 Preparing the seed data
      2. 32.2.2 Configuring Entity Framework Core
      3. 32.2.3 Creating and applying the migration
    3. 32.3 Adding the Bootstrap CSS framework
    4. 32.4 Configuring the services and middleware
    5. 32.5 Creating a controller and view
    6. 32.6 Creating a Razor Page
    7. 32.7 Running the example application
  43. 33 Using Blazor Server, part 1
    1. 33.1 Preparing for this chapter
    2. 33.2 Understanding Blazor Server
      1. 33.2.1 Understanding the Blazor Server advantages
      2. 33.2.2 Understanding the Blazor Server disadvantages
      3. 33.2.3 Choosing between Blazor Server and Angular/React/Vue.js
    3. 33.3 Getting started with Blazor
      1. 33.3.1 Configuring ASP.NET Core for Blazor Server
      2. 33.3.2 Creating a Razor Component
    4. 33.4 Understanding the basic Razor Component features
      1. 33.4.1 Understanding Blazor events and data bindings
      2. 33.4.2 Working with data bindings
    5. 33.5 Using class files to define components
      1. 33.5.1 Using a code-behind class
      2. 33.5.2 Defining a Razor Component class
    6. Summary
  44. 34 Using Blazor Server, part 2
    1. 34.1 Preparing for this chapter
    2. 34.2 Combining components
      1. 34.2.1 Configuring components with attributes
      2. 34.2.2 Creating custom events and bindings
    3. 34.3 Displaying child content in a component
      1. 34.3.1 Creating template components
      2. 34.3.2 Using generic type parameters in template components
      3. 34.3.3 Cascading parameters
    4. 34.4 Handling errors
      1. 34.4.1 Handling connection errors
      2. 34.4.2 Handling uncaught application errors
      3. 34.4.3 Using error boundaries
    5. Summary
  45. 35 Advanced Blazor features
    1. 35.1 Preparing for this chapter
    2. 35.2 Using component routing
      1. 35.2.1 Preparing the Razor Page
      2. 35.2.2 Adding routes to components
      3. 35.2.3 Navigating between routed components
      4. 35.2.4 Receiving routing data
      5. 35.2.5 Defining common content using layouts
    3. 35.3 Understanding the component lifecycle methods
      1. 35.3.1 Using the lifecycle methods for asynchronous tasks
    4. 35.4 Managing component interaction
      1. 35.4.1 Using references to child components
      2. 35.4.2 Interacting with components from other code
      3. 35.4.3 Interacting with components using JavaScript
    5. Summary
  46. 36 Blazor forms and data
    1. 36.1 Preparing for this chapter
      1. 36.1.1 Dropping the database and running the application
    2. 36.2 Using the Blazor form components
      1. 36.2.1 Creating custom form components
      2. 36.2.2 Validating form data
      3. 36.2.3 Handling form events
    3. 36.3 Using Entity Framework Core with Blazor
      1. 36.3.1 Understanding the EF Core context scope issue
      2. 36.3.2 Understanding the repeated query issue
    4. 36.4 Performing CRUD operations
      1. 36.4.1 Creating the list component
      2. 36.4.2 Creating the details component
      3. 36.4.3 Creating the editor component
    5. 36.5 Extending the Blazor form features
      1. 36.5.1 Creating a custom validation constraint
      2. 36.5.2 Creating a valid-only submit button component
    6. Summary
  47. 37 Using Blazor WebAssembly
    1. 37.1 Preparing for this chapter
      1. 37.1.1 Dropping the database and running the application
    2. 37.2 Setting Up Blazor WebAssembly
      1. 37.2.1 Creating the shared project
      2. 37.2.2 Creating the Blazor WebAssembly project
      3. 37.2.3 Preparing the ASP.NET Core project
      4. 37.2.4 Adding the solution references
      5. 37.2.5 Opening the projects
      6. 37.2.6 Completing the Blazor WebAssembly configuration
      7. 37.2.7 Testing the placeholder components
    3. 37.3 Creating a Blazor WebAssembly component
      1. 37.3.1 Importing the data model namespace
      2. 37.3.2 Creating a component
      3. 37.3.3 Creating a layout
      4. 37.3.4 Defining CSS styles
    4. 37.4 Completing the Blazor WebAssembly Form application
      1. 37.4.1 Creating the details component
      2. 37.4.2 Creating the editor component
    5. Summary
  48. 38 Using ASP.NET Core Identity
    1. 38.1 Preparing for this chapter
    2. 38.2 Preparing the project for ASP.NET Core Identity
      1. 38.2.1 Preparing the ASP.NET Core Identity database
      2. 38.2.2 Configuring the application
      3. 38.2.3 Creating and applying the Identity database migration
    3. 38.3 Creating user management tools
      1. 38.3.1 Preparing for user management tools
      2. 38.3.2 Enumerating user accounts
      3. 38.3.3 Creating users
      4. 38.3.4 Editing users
      5. 38.3.5 Deleting users
    4. 38.4 Creating role management tools
      1. 38.4.1 Preparing for role management tools
      2. 38.4.2 Enumerating and deleting roles
      3. 38.4.3 Creating roles
      4. 38.4.4 Assigning role membership
    5. Summary
  49. 39 Applying ASP.NET Core Identity
    1. 39.1 Preparing for this chapter
    2. 39.2 Authenticating users
      1. 39.2.1 Creating the login feature
      2. 39.2.2 Inspecting the ASP.NET Core Identity cookie
      3. 39.2.3 Creating a Sign-Out page
      4. 39.2.4 Testing the authentication feature
      5. 39.2.5 Enabling the Identity authentication middleware
    3. 39.3 Authorizing access to endpoints
      1. 39.3.1 Applying the authorization attribute
      2. 39.3.2 Enabling the authorization middleware
      3. 39.3.3 Creating the access denied endpoint
      4. 39.3.4 Creating the seed data
      5. 39.3.5 Testing the authentication sequence
    4. 39.4 Authorizing access to Blazor applications
      1. 39.4.1 Performing authorization in Blazor components
      2. 39.4.2 Displaying content to authorized users
    5. 39.5 Authenticating and authorizing web services
      1. 39.5.1 Building a simple JavaScript client
      2. 39.5.2 Restricting access to the web service
      3. 39.5.3 Using cookie authentication
      4. 39.5.4 Using bearer token authentication
      5. 39.5.5 Creating tokens
      6. 39.5.6 Authenticating with tokens
      7. 39.5.7 Restricting access with tokens
      8. 39.5.8 Using tokens to request data
    6. Summary
  50. index

Product information

  • Title: Pro ASP.NET Core 7, Tenth Edition
  • Author(s): Adam Freeman
  • Release date: November 2023
  • Publisher(s): Manning Publications
  • ISBN: 9781633437821