Cover....1
Title Page....2
Copyright and Credit....3
Dedications....4
Contributors....5
Table of Contents....8
Part 1: ASP.NET Core 9 Fundamentals....22
Introducing ASP.NET Core 9 Concepts....24
Technical requirements....24
Why ASP.NET Core 9?....25
Comparing .NET and .NET Framework....27
Preparing our development environment....28
The development tool....28
SDK and runtime....29
CLI (Command-Line Interface)....29
Windows installation....29
macOS installation....31
Linux installation....32
Visual Studio Code....32
Testing the development environment....33
What is new in ASP.NET Core 9?....37
Summary....37
Chapter 2: Building Dynamic UIs with Razor Pages, MVC, and Blazor....38
Technical requirements....38
Learning about the ASP.NET Core UI....39
Rendering the UI....39
Implementing a UI server render model with Razor Pages and ASP.NET MVC....40
ASP.NET Core Razor Pages....40
ASP.NET Core MVC....56
Exploring UI client rendering with Blazor and JavaScript frameworks....63
Rich UIs with Blazor....63
ASP.NET Core 9 and JavaScript frameworks....67
Working with hybrid solutions....69
Summary....72
Chapter 3: Crafting Web APIs for Service Delivery....74
Technical requirements....74
Delivering business as a service....75
HTTP verbs and conventions....76
REST....76
HTTP status codes....77
Exploring minimal APIs....78
Implementing APIs using the controller-based approach....85
Creating a controller-based API....86
Understanding the product controller....87
ControllerBase utilities....89
Working with binding....91
Performing validations....94
Working with documentation....95
Documenting APIs with Swagger....96
Summary....106
Chapter 4: Real-Time Interactions with SignalR....108
Technical requirements....108
What is SignalR?....109
Understanding the concepts of Servers and Clients....111
Working with a task management application....111
Creating the Hub....114
Preparing the server application....116
Preparing the client application....117
Understanding the client and server communication flow....120
Working with streaming....122
Implementing basic streaming....123
Hosting the ASP.NET Core SignalR application....128
The basics of hosting a SignalR application....128
Summary....129
Part 2: Data and Security....130
Chapter 5: Working with Data and Persistence....132
Technical requirements....132
Docker installation....133
Azure Data Studio....133
Connecting to a SQL database....133
Preparing SQL Server....134
Using the SQL client....137
Understanding SQL, NoSQL, ORM, and Micro ORM....140
SQL versus NoSQL....140
ORM and Micro ORM....143
Working with EF Core and Dapper....148
EF Core....148
Dapper....157
Summary....159
Chapter 6: Enhancing Security and Quality....160
Technical requirements....161
Understanding the security principles of web-based applications....161
Security topics in web applications....162
Comparing authorization and authentication....164
Authentication....165
Authorization....166
Understanding OAuth 2.0 and OIDC....167
Working with the ASP.NET Core Identity framework....169
Understanding the ASP.NET Core Identity architecture....169
Getting started with integrating ASP.NET Core Identity....170
Configuring the database context....172
Updating the database....173
Adding ASP.NET Core Identity services and routes....175
Securing APIs with ASP.NET Core Identity....181
Securing application routes....183
Requesting an API with the access token....188
Strengthening application security....191
Managing secrets properly....192
Enforcing HTTPS and working with CORS....195
Preventing common vulnerabilities....197
Summary....199
Part 3: Applying Best Practices....200
Chapter 7: Adding Capabilities to Applications....202
Technical requirements....202
Working with ASP.NET Core 9 best practices....203
HTTP request best practices....203
Asynchronous requests and I/O optimization....208
Improving performance with a cache strategy and making the application resilient....210
Caching strategies....211
Integrating Redis in our application....212
Working with cache in the controller class....213
Configuring Redis Insight....218
Resilience mechanisms....220
Understanding and implementing logging and monitoring....223
Introduction to logging and monitoring....224
Summary....229
Chapter 8: Enhancing Applications with Middleware in ASP.NET Core 9....230
Technical requirements....230
Knowing the middleware pipeline....231
Understanding middleware flow....233
Benefits of middleware and best practices....235
Implementing custom middleware....237
Working with factory-based middleware....240
Adding capabilities to applications using middleware....242
Global error handling....243
Adding request logging....246
Rate limiting....248
Creating an extension method for middleware registration....252
Summary....255
Chapter 9: Managing Application Settings....256
Technical requirements....256
Understanding IConfiguration concepts and abstractions....257
IConfiguration interface....257
Working with configuration providers....259
Adding configuration providers....259
Creating a custom configuration provider....261
Learning the Options pattern....263
What is the Options pattern?....263
Implementing the Options pattern....265
Working with dynamic configurations and behaviors....270
Working with dynamic settings....270
Connecting an ASP.NET Core 9 application to Azure App Configuration....282
Summary....289
Part 4: Hosting, Deploying, and Preparing to the Cloud....290
Chapter 10: Deploying and Hosting Applications....292
Technical requirements....292
Preparing to publish your application and host locally....293
The importance of the publishing process....293
Generating a publishing package....294
Publishing the solution in a cloud environment....297
Creating Azure app services and database resources....298
Configuring Azure SQL Server....303
Publishing an application with Visual Studio Code....306
Understanding the Docker principles and how to package the application in a container....309
Understanding what a container is....309
Understanding Docker fundamentals....311
Packing the UrlShortener application....313
Generating a container image....316
Running a Docker container....317
Understanding the DevOps approach with CI/CD....319
CI....320
CD....321
Automating with GitHub Actions....323
Summary....332
Chapter 11: Cloud-Native Development with ASP.NET Core 9....334
Technical requirements....334
Creating a cloud-native mindset....335
Understanding the service layers in a cloud environment....335
Cloud-native development best practices....337
Going beyond code development....339
Working with cloud-native tools....339
Getting to know CNCF....342
Working with CNCF....342
The twelve-factor app principles....344
Code base....345
Dependencies....346
Config....346
Backing services....348
Build, release, run....349
Processes....351
Port binding....352
Concurrency....354
Disposability....355
Dev/prod parity....357
Logs....358
Admin process....360
The importance of the twelve-factor app methodology....361
Understanding cloud architecture principles....361
Working with modern design architecture....362
Event-driven architectures....362
Understanding microservices....366
Considering deployment strategies....368
Summary....369
Index....370
Other Books You May Enjoy....1
Make the most of the ASP.NET Core platform to create robust, high-quality solutions using approaches adopted by leading companies
Build cutting-edge web applications using ASP.NET Core 9 with this comprehensive guide from Microsoft MVP Albert Tanure, a seasoned .NET expert with over 20 years of experience as a cloud solutions architect. Albert brings unparalleled expertise in building modern web applications to ASP.NET Core 9.0 Essentials to help you kickstart your journey on the right foot.
Starting with the platform’s fundamental concepts, you’ll work through practical exercises to develop web applications with powerful UI frameworks, deliver flexible and scalable solutions through an API approach, and explore advanced topics such as customizing request flows and implementing robust security measures. You’ll get to grips with cloud-native practices to prepare your applications for cloud environments. Whether you’re a beginner or an experienced developer, this book is your guide to building modern, secure, and adaptable web applications with ASP.NET Core.
By the end of this book, you’ll be proficient in leveraging the advanced features of ASP.NET Core 9 to create cloud-ready web applications for diverse market segments.
ASP.NET Core 9.0 Essentials is for developers engaged in both backend and frontend solution development as well as software engineers who want to craft innovative web-based solutions using ASP.NET Core technology. To fully benefit from this book, you should be familiar with software development, object-oriented programming, and high-level languages such as C# and Java, and have some experience with HTML and CSS.