0%

Book Description

Explore the tools and techniques to build scalable and secured restful web services and web applications using C# 8 and ASP. NET CORE 3.1

Key Features

  • Delve into MVC patterns, configuration, routing, and deployment to build professional-grade applications
  • Learn how to integrate ASP applications with the JavaScript frameworks React, Vue, and Angular
  • Improve the performance of applications and the development team by implementing advanced ASP.NET Core concepts

Book Description

ASP.NET has been the preferred choice of web developers for a long time. With ASP.NET Core 3, Microsoft has made internal changes to the framework along with introducing new additions that will change the way you approach web development. This second edition has been thoroughly updated to help you make the most of the latest features in the framework, right from gRPC and conventions to Blazor, which has a new chapter dedicated to it.

You'll begin with an overview of the essential topics, exploring the Model-View-Controller (MVC) pattern, various platforms, dependencies, and frameworks. Next, you'll learn how to set up and configure the MVC environment, before delving into advanced routing options. As you advance, you'll get to grips with controllers and actions to process requests, and later understand how to create HTML inputs for models. Moving on, you'll discover the essential aspects of syntax and processes when working with Razor. You'll also get up to speed with client-side development and explore the testing, logging, scalability, and security aspects of ASP.NET Core. Finally, you'll learn how to deploy ASP.NET Core to several environments, such as Azure, Amazon Web Services (AWS), and Docker.

By the end of the book, you'll be well versed in development in ASP.NET Core and will have a deep understanding of how to interact with the framework and work cross-platform.

What you will learn

  • Understand the new capabilities of ASP.NET Core 3.1
  • Become well versed in how to configure ASP.NET Core to use it to its full potential
  • Create controllers and action methods, and understand how to maintain state
  • Implement and validate forms and retrieve information from them
  • Improve productivity by enforcing reuse, process forms, and effective security measures
  • Delve into the new Blazor development model
  • Deploy ASP.NET Core applications to new environments, such as Microsoft Azure, AWS, and Docker

Who this book is for

If you are a developer with basic knowledge of ASP.NET MVC and want to build powerful applications, then this book is for you. Developers who want to explore the latest changes in ASP.NET Core 3.1 to build professional-level applications will also find this book useful. Familiarity with C#, ASP.NET Core, HTML, and CSS is expected to get the most out of this book.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Modern Web Development with ASP.NET Core 3 Second Edition
  3. Dedication
  4. About Packt
    1. Why subscribe?
  5. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  7. Section 1: The Fundamentals of ASP.NET Core 3
  8. Getting Started with ASP.NET Core
    1. Technical requirements
    2. Getting started
    3. Beginning with .NET Core
    4. Supported platforms
    5. Dependencies and frameworks
    6. Targeting .NET Core or the full .NET framework
    7. Understanding the generic host
    8. Understanding the MVC pattern
    9. Getting your context
    10. Working with the context
    11. Understanding the OWIN pipeline
    12. Hosting ASP.NET Core
    13. Kestrel
    14. WebListener/HTTP.sys
    15. IIS
    16. NGINX
    17. Apache
    18. Configuration
    19. Features
    20. Launch configuration
    21. Setting the listen port and address
    22. Using the command line
    23. Using environment variables
    24. Using launchSettings.json
    25. Using code
    26. Setting ports dynamically
    27. Inversion of control and dependency injection
    28. Validating dependencies
    29. Knowing the environments
    30. Understanding the project templates
    31. What's new since version 2.0?
    32. ASP.NET Core 2.1
    33. SignalR
    34. Razor class libraries
    35. Razor pages improvements
    36. New partial tag helper
    37. Top-level parameter validation
    38. Identity UI library and scaffolding
    39. Virtual authentication schemes
    40. HTTPS by default
    41. GDPR-related template changes
    42. MVC functional test improvements
    43. API conventions and supporting types
    44. Generic host builder
    45. Updated SPA templates
    46. ASP.NET Core 2.2
    47. API code analyzers
    48. Health check API
    49. Endpoint routing
    50. Problem details (RFC 7807) support
    51. ASP.NET Core 3.0
    52. C# 8.0
    53. .NET Standard 2.1
    54. Blazor
    55. Built-in JSON support
    56. HTTP/2 support
    57. gRPC
    58. IdentityServer integration
    59. Endpoint routing
    60. Migrating to ASP.NET Core 3.x
    61. Version set
    62. The NuGet and dotnet tools
    63. Summary
    64. Questions
  9. Configuration
    1. Technical requirements
    2. Getting started
    3. Configurations in .NET Core
    4. Providers
    5. File-based providers
    6. JSON provider
    7. XML provider
    8. INI provider
    9. Other providers
    10. User secrets
    11. Azure Key Vault
    12. Command line
    13. Environment variables
    14. Memory
    15. Docker
    16. Default providers
    17. Creating a custom provider
    18. Using configuration values
    19. Getting and setting values explicitly
    20. Configuration sections
    21. Getting all values
    22. Binding to classes
    23. Injecting values
    24. Retrieving named configuration options
    25. Reloading and handling change notifications
    26. Running pre- and post-configuration actions
    27. Changes from version 2.x
    28. Configuring the runtime host
    29. Understanding feature toggling
    30. Included feature filters
    31. Percentage filter
    32. Time window filter
    33. Custom feature filters
    34. Consistency between checks
    35. Disabled features handler
    36. Summary
    37. Questions
  10. Routing
    1. Technical requirements
    2. Getting started
    3. Endpoint routing
    4. Route configuration
    5. Creating routing tables
    6. Fallback endpoints
    7. Using route templates
    8. Matching route parameters
    9. Using dynamic routing
    10. Selecting routes from attributes
    11. Using special routes
    12. Host selection from attributes
    13. Setting route defaults
    14. Routing to inline handlers
    15. Applying route constraints
    16. HTTP methods
    17. Default constraints
    18. Creating custom constraints
    19. Route data tokens
    20. Routing to areas
    21. Using routing attributes
    22. Defining routes
    23. Default routes
    24. Constraining routes
    25. Defining areas
    26. Specifying action names
    27. Defining non-actions
    28. Restricting routes
    29. Setting route values
    30. Error handling in routing
    31. Routing errors to controller routes
    32. Using developer exception pages
    33. Using a catch-all route
    34. Using status code pages middleware
    35. Status code pages
    36. Routing to specific status code pages
    37. Any status code
    38. Summary
    39. Questions
  11. Controllers and Actions
    1. Technical requirements
    2. Getting started
    3. Using controllers
    4. Controller base classes
    5. POCO controllers
    6. Adding context to POCO controllers
    7. Intercepting actions in POCO controllers
    8. Finding controllers
    9. Controller life cycle
    10. Actions
    11. Finding actions
    12. Synchronous and asynchronous actions
    13. Getting the context
    14. Action constraints
    15. Action parameters
    16. Model binding
    17. Body
    18. Form
    19. Header
    20. Query string
    21. Route
    22. Dependency injection
    23. Custom binders
    24. Property binding
    25. Input formatters
    26. Explicit binding
    27. Canceling requests
    28. Model validation
    29. Action results
    30. Redirecting
    31. Streaming
    32. Error handling
    33. Response caching
    34. Maintaining the state
    35. Using the request
    36. Using form data
    37. Using the query string
    38. Using the route
    39. Using cookies
    40. Using sessions
    41. Using the cache
    42. In-memory cache
    43. Distributed cache
    44. Redis
    45. SQL Server
    46. Using temporary data
    47. Comparing state maintenance techniques
    48. Dependency injection
    49. Globalization and localization
    50. Summary
    51. Questions
  12. Views
    1. Technical requirements
    2. Getting started
    3. Understanding views
    4. Understanding the view life cycle
    5. Locating views
    6. Using view location expanders
    7. Using view engines
    8. Logging and diagnostics
    9. View compilation
    10. Passing data to views
    11. Using the model
    12. Using the ViewBag property
    13. Using temporary data
    14. Understanding view layouts
    15. Understanding partial views
    16. Passing data to partial views
    17. Finding partial views
    18. Understanding the special view files
    19. Understanding the view options
    20. Referencing the base path of the application
    21. Using areas
    22. Dependency injection
    23. Using translations
    24. Using resources
    25. Using translated views
    26. Summary
    27. Questions
  13. Section 2: Improving Productivity
  14. Using Forms and Models
    1. Technical requirements
    2. Getting started
    3. Using the form context
    4. Working with the model
    5. Using models of anonymous types
    6. Using HTML helpers
    7. Forms
    8. Single-line text boxes
    9. Multi-line text boxes
    10. Passwords
    11. Dropdowns
    12. List boxes
    13. Radio buttons
    14. Checkboxes
    15. Hidden values
    16. Links
    17. Labels
    18. Raw HTML
    19. IDs, names, and values
    20. Generic editor and display
    21. Utility methods and properties
    22. Validation messages
    23. Custom helpers
    24. Using templates
    25. Enforcing model binding
    26. Model binders
    27. Model binding sources
    28. Dynamic binding
    29. Model validation
    30. Server-side validation
    31. Configuration
    32. Data annotation validation
    33. Error messages
    34. Self-validation
    35. Custom validation
    36. Preventing validation
    37. Automatic validation
    38. Client-side model validation
    39. Configuration
    40. Custom validation
    41. Using AJAX for validation
    42. Validation
    43. Enforcing restrictions
    44. Returning content from AJAX
    45. Uploading files
    46. Direct access to submitted files
    47. Summary
    48. Questions
  15. Implementing Razor Pages
    1. Technical requirements
    2. Getting started
    3. Assets search order
    4. Working with the page model
    5. Understanding page handlers
    6. Doing model binding
    7. Doing model validation
    8. Maintaining state
    9. Using view layouts
    10. Using partial views
    11. Using areas
    12. Special files
    13. Using filters
    14. Using dependency injection
    15. Configuring options
    16. Understanding page routes
    17. Enforcing security
    18. Using the [Authorize] attribute
    19. Conventions
    20. Cross-site request scripting
    21. Summary
    22. Questions
  16. API Controllers
    1. Technical requirements
    2. Getting started with web APIs
    3. Understanding REST
    4. Model binding
    5. Authorizing access to resources
    6. Using JWTs
    7. Applying OpenAPI REST conventions
    8. Returning validation results
    9. Performing content negotiation
    10. Output formatters
    11. Handling null values
    12. Handling errors
    13. Understanding API versioning
    14. Using header values
    15. Using the query string
    16. Deprecating versions
    17. Default versions
    18. Version mapping
    19. Invalid versions
    20. Generating API documentation
    21. Adding API documentation
    22. Serving OData
    23. Setting up OData
    24. Getting metadata
    25. Listing collections
    26. Entity metadata
    27. Querying
    28. Filtering an entity
    29. Projections
    30. Paging
    31. Sorting
    32. Expansion
    33. Counting
    34. Configuring options
    35. Limits
    36. Maximum returnable records
    37. Expansion
    38. Summary
    39. Questions
  17. Reusable Components
    1. Technical requirements
    2. Diving into the view components
    3. Discovering view components
    4. Using view components
    5. View component results
    6. Dependency injection
    7. View components versus partial views
    8. Exploring the tag helpers
    9. Understanding the properties of a tag helper
    10. Restricting the applicability of a tag helper
    11. Discovering tag helpers
    12. Dependency injection
    13. Studying the included tag helpers
    14. The <a> tag
    15. The <cache> tag
    16. The <component> tag
    17. The <distributed-cache> tag
    18. The <environment> tag
    19. The <form> tag
    20. The <script> tag
    21. The <link> tag
    22. The <select> tag
    23. The <partial> tag
    24. Validation message and summary
    25. Tag helper components
    26. Partial views
    27. Partial views versus view components
    28. Understanding Razor class libraries
    29. Referencing static content
    30. Referencing external components
    31. Summary
    32. Questions
  18. Understanding Filters
    1. Technical requirements
    2. Filters in the pipeline
    3. Understanding the filter types
    4. Synchronous versus asynchronous
    5. Filter scope
    6. Execution order
    7. Applying filters through attributes
    8. Filter ordering
    9. Factories and providers
    10. DI
    11. Accessing the context
    12. Applying authorization filters
    13. Authorization policies
    14. Resource filters
    15. Understanding action filters
    16. Result filters
    17. Exception filters
    18. Razor page filters
    19. Always-run-result filters
    20. Summary
    21. Questions
  19. Security
    1. Technical requirements
    2. Authenticating users
    3. Using claims
    4. Windows authentication
    5. Custom authentication
    6. Identity
    7. Adding custom properties
    8. Updating the user interface
    9. Using the Identity provider
    10. Using IdentityServer
    11. Using Azure Active Directory
    12. Using social logins
    13. Facebook
    14. Twitter
    15. Google
    16. Microsoft
    17. Cookie security
    18. Supporting SameSite cookies
    19. Authorizing requests
    20. Authorization based on roles
    21. Policy-based authorization
    22. Authorization handlers
    23. Resource-based authorization
    24. Allowing anonymous access
    25. Checking requests for forgery
    26. Applying HTML encoding
    27. Working with HTTPS
    28. Certificates
    29. Hosting our app
    30. IIS Express
    31. Kestrel
    32. HTTP.sys
    33. Forcing HTTPS
    34. Redirecting to HTTPS
    35. Using HSTS
    36. HSTS preload
    37. Understanding CORS
    38. Using data protection
    39. Protecting static files
    40. Using an action to retrieve files
    41. Using middleware to enforce security
    42. Learning about the GDPR
    43. Required cookies
    44. Personal data
    45. Binding security
    46. Summary
    47. Questions
  20. Section 3: Advanced Topics
  21. Logging, Tracing, and Diagnostics
    1. Technical requirements
    2. Introducing the .NET Core Common Logging framework
    3. Using logging services
    4. Defining log levels
    5. Using logging providers
    6. Filtering logs
    7. Writing custom log providers
    8. Using DI with the log providers
    9. Using logging attributes
    10. Writing custom logging middleware
    11. Using tracing and diagnostics
    12. Using performance (event) counters for obtaining metrics
    13. Included counters
    14. Custom counters
    15. Performance monitoring
    16. Tracing
    17. Trace dumps
    18. Using telemetry
    19. Using trace identifiers
    20. Azure Application Insights
    21. Sending custom events
    22. AWS CloudWatch
    23. New Relic
    24. Performing health checking
    25. Summary
    26. Questions
  22. Understanding How Testing Works
    1. Technical requirements
    2. Getting started with unit tests
    3. Writing unit tests
    4. Unit test frameworks
    5. MSTest
    6. NUnit
    7. xUnit
    8. Test setup
    9. Injecting dependencies
    10. Mocking
    11. Assertions
    12. User interface
    13. Using the command line
    14. Limitations of unit tests
    15. Working on integration tests
    16. Summary
    17. Questions
  23. Client-Side Development
    1. Technical requirements
    2. Introducing client-side development
    3. Using LibMan
    4. Using Node.js
    5. Calling Node from .NET Core
    6. Serving SPA files
    7. Using SPA templates
    8. Using TypeScript
    9. Summary
    10. Questions
  24. Improving Performance and Scalability
    1. Technical requirements
    2. Getting started
    3. MiniProfiler
    4. Stackify Prefix
    5. Hosting ASP.NET Core
    6. Choosing the best host
    7. Configuration tuning
    8. Maximum number of simultaneous connections
    9. Limits
    10. Timeouts
    11. Understanding bundling and minification
    12. Using asynchronous actions
    13. Improving performance with caching
    14. Caching data
    15. In-memory cache
    16. Distributed cache
    17. Caching action results
    18. Caching views
    19. Compressing responses
    20. Buffering responses
    21. Summary
    22. Questions
  25. Real-Time Communication
    1. Technical requirements
    2. Setting up SignalR
    3. Learning core concepts
    4. Hosting a hub
    5. Choosing communication protocols
    6. Automatic reconnection
    7. Message serialization
    8. Exploring the SignalR context
    9. Using the query string
    10. Knowing the message targets
    11. Communicating from the outside
    12. Communication from the same web application
    13. Communicating from a different application
    14. Using user authentication
    15. Logging
    16. Summary
    17. Questions
  26. Introducing Blazor
    1. Technical requirements
    2. Getting started with Blazor
    3. Hosting models
    4. Implementing Blazor
    5. Implementing Blazor Server
    6. Implementing Blazor WebAssembly
    7. Comparing Server and WebAssembly
    8. Pages
    9. Razor syntax
    10. Namespace imports
    11. Partial classes
    12. Pages as code
    13. Pages as components
    14. Page layouts
    15. Routing
    16. Page routes
    17. Route constraints
    18. A catch-all route
    19. Parameter binding from route
    20. Page navigation
    21. Building components
    22. The <component> tag helper
    23. Blazor component properties
    24. Cascading properties
    25. Catch-all properties
    26. Child content properties
    27. Components with generic parameters
    28. Lists of components
    29. Locating components
    30. Rendering modes
    31. The component life cycle
    32. Reusing components in different projects
    33. Accessing the HTTP context
    34. Sample components
    35. Working with forms
    36. Form editing
    37. Form context
    38. Form components
    39. Form validation
    40. Working with DOM elements
    41. Two-way binding
    42. Event handling
    43. Referencing elements
    44. Updating the state
    45. DI
    46. Injecting services
    47. Registered services
    48. Scoped lifetime
    49. JavaScript interoperability
    50. Calling JavaScript functions from .NET
    51. Calling .NET methods from JavaScript
    52. Maintaining state
    53. Making HTTP calls
    54. Applying security
    55. Requesting authorization
    56. Getting the current user
    57. Checking permissions explicitly
    58. CORS
    59. Unit testing
    60. Summary
    61. Questions
  27. gRPC and Other Topics
    1. Technical requirements
    2. Using areas for organizing code
    3. The use of areas in code
    4. Tag and HTML helpers
    5. Working with static files and folders
    6. Configuration
    7. Allowing directory browsing
    8. Serving static files
    9. Serving default documents
    10. Applying security
    11. File providers
    12. Application lifetime events
    13. Working with embedded resources
    14. Hosting extensions
    15. Hosting startup
    16. Hosting background services
    17. ASP.NET Core model conventions
    18. Applying URL rewriting
    19. URL redirection
    20. URL rewriting
    21. Runtime evaluation
    22. Redirecting to HTTPS
    23. Platform-specific
    24. Enforcing URL rewriting
    25. Using EF Core
    26. Registering DbContext
    27. Using asynchronous methods
    28. Eager loading
    29. Initializing a database
    30. Showing migration errors and running migrations
    31. Integrating an EF context with an HTTP context
    32. Building a REST service
    33. Understanding the gRPC framework
    34. Interface definition
    35. Messaging kinds
    36. Hosting a service
    37. Request context
    38. Interceptors
    39. Listening options
    40. Using HTTP client factories
    41. Summary
    42. Questions
  28. Application Deployment
    1. Technical requirements
    2. Deploying the application manually
    3. Setting the target framework
    4. Self-contained deployments and runtimes
    5. Real-time rebuilding
    6. Deploying with Visual Studio 
    7. Deploying through IIS
    8. Deploying with NGINX
    9. Deploying to Azure
    10. Deploying to AWS
    11. Deploying with Docker
    12. Deploying as a Windows service
    13. Summary
    14. Questions
  29. Appendix A: The dotnet Tool
    1. The dotnet Tool
    2. Build
    3. Creating projects from templates
    4. Unit testing
    5. Managing package references
    6. Run
    7. Publish
    8. NuGet
    9. Global tools
    10. User secrets
    11. File watcher
    12. EF Core
  30. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Chapter 15
    16. Chapter 16
    17. Chapter 17
    18. Chapter 18
    19. Chapter 19
  31. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
18.191.189.85