
Customizing ASP.NET Core 6.0
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
Key Features
Second edition updated and enhanced to cover the latest .NET 6 features and changes
Learn authentication and authorization techniques for securing your web apps from a .NET veteran
Discover best practices for configuring ASP.NET Core, from user interface design to hosting it on platforms
Book DescriptionASP.NET Core is packed full of hidden features for building sophisticated web applications - but if you don't know how to customize it, you're not making the most of its capabilities. Customizing ASP.NET Core 6.0 is a book that will teach you all about tweaking the knobs at various layers and take experienced programmers' skills to a new level. This updated second edition covers the latest features and changes in the .NET 6 LTS version, along with new insights and customization techniques for important topics such as authentication and authorization. You'll also learn how to work with caches and change the default behavior of ASP.NET Core apps. This book will show you the essential concepts relating to tweaking the framework, such as configuration, dependency injection, routing, action filters, and more. As you progress, you'll be able to create custom solutions that meet the needs of your use case with ASP.NET Core. Later chapters will cover expert techniques and best practices for using the framework for your app development needs, from UI design to hosting. Finally, you'll focus on the new endpoint routing in ASP.NET Core to build custom endpoints and add third-party endpoints to your web apps for processing requests faster. By the end of this book, you'll be able to customize ASP.NET Core to develop better, more robust apps.What you will learn
Explore various application configurations and providers in ASP.NET Core 6
Enable and work with caches to improve the performance of your application
Understand dependency injection in .NET and learn how to add third-party DI containers
Discover the concept of middleware and write your middleware for ASP.NET Core apps
Create various API output formats in your API-driven projects
Get familiar with different hosting models for your ASP.NET Core app
Who this book is forThis book is for .NET developers who've already covered the basics and are now looking to learn more about changing default behaviors of the framework to help improve the performance of their applications. Intermediate-level knowledge of ASP.NET core and C# is a must before you get started; there's no refresher and very little theory in this book.
All prices
More details
Other editions
Additional editions

Person
Juergen Gutsch is a .NET-addicted web developer. He has worked with .NET and ASP.NET since the early versions in 2002. Before that, he wrote server-side web applications using classic ASP. He is also an active part of the .NET developer community. Juergen writes for the dotnetpro magazine, one of the most popular German-speaking developer magazines. He also publishes articles in English on his blog, ASP.NET Hacker, and contributes to several open source projects. Juergen has been a Microsoft MVP since 2015. The best way to contact him is by using Twitter at sharpcms. He works as a developer, consultant, and trainer for the digital agency YOO Inc., located in Basel, Switzerland. YOO Inc. serves national as well as international clients and specializes in creating custom digital solutions for distinct business needs.
Content
Customizing Logging
Customizing App Configuration
Customizing Dependency Injection
Configuring and Customizing HTTPS with Kestrel
Configuring WebHostBuilder
Using Different Hosting Models
Using IHostedService and BackgroundService
Writing Custom Middleware
Working with Endpoint Routing
Customizing ASP.NET Core Identity
Configuring Identity Management
Content Negotiation Using a Custom OutputFormatter
Managing Inputs with Custom ModelBinder
Creating a Custom ActionFilter
Working with Caches
Creating Custom TagHelper
Preface
ASP.NET Core is the most powerful web framework provided by Microsoft and is full of hidden features that make it even more powerful and useful.
Your application should not be made to match the framework; your framework should be able to do what your application really needs. With this book, you will learn how to find the hidden screws you can turn to get the most out of the framework.
Developers working with ASP.NET Core will be able to put their knowledge to work with this practical guide to customizing ASP.NET Core. The book provides a hands-on approach to implementation and its associated methodologies that will have you up and running and productive in no time.
This book is a compact collection of default ASP.NET Core behaviors you might want to change and step-by-step explanations of how to do so.
By the end of this book, you will know how to customize ASP.NET Core to get an optimized application out of it according to your individual needs.
ASP.NET Core architecture overview
To follow the next chapters, you should be familiar with the base architecture of ASP.NET Core and its components. This book tackles almost all of the components of the architecture.
The following figure shows the base architecture overview of ASP.NET Core 6.0. Let's quickly go through the components shown here from the bottom to the top layer:
At the bottom, there is the Host layer. This is the layer that bootstraps the web server and all the stuff that is needed to start up an ASP.NET Core application, including logging, configuration, and the service provider. This layer creates the actual request objects and their dependencies that are used in the layers above.
The next layer above Host is the Middleware layer. This layer works with the request object or manipulates it. This attaches the middleware to the request object. It executes the middleware for things such as error handling, authenticating HSTS, CORS, and so on.
Above that, there is the Routing layer, which routes the request to the endpoints depending on the route patterns defined. Endpoint routing is the new player from ASP.NET Core 3.1 and separates routing from the UI layers above to enable routing for different endpoints, including Blazor, gRPC, and SignalR. As a reminder: in previous versions of ASP.NET Core, routing was part of the MVC layer, and every other UI layer needed to implement its own routing.
The actual endpoints are provided by the fourth layer, the UI layer, which contains the well-known UI frameworks Blazor, gRPC, SignalR, and MVC. This is where you will do most of your work as an ASP.NET Core developer.
Lastly, above MVC, you will find WebAPI and Razor Pages.
What is covered in this book?
This book doesn't cover all the topics mentioned in the architecture overview. This book covers most topics of the host layer because that is the layer that contains the most things you might need to customize. This book tackles middleware and routing, as well as MVC features and some more WebAPI topics, where you can do some magic tricks.
At the beginning of each chapter, we will indicate to which level the topic belongs.
What is not covered and why?
This book doesn't cover Razor Pages, SignalR, gRPC, and Blazor.
The reason is that gRPC and SignalR are already very specialized, and don't really need to be customized. Blazor is a new member of the ASP.NET Core family and is not widely used yet. Also, the author isn't familiar enough with Blazor to know all the screws to customize it. Razor Pages is on top of the MVC framework and customizations for MVC are also valid for Razor Pages.
Who this book is for
This book is for web developers working with ASP.NET Core, who might need to change default behaviors to get things done. Readers should have basic knowledge of ASP. NET Core and C#, since this book does not cover the basics of those technologies. Readers should also have a good knowledge of Visual Studio, Visual Studio Code, or any other code editor that supports ASP.NET Core and C#.
What this book covers
Chapter 1, Customizing Logging, teaches you how to customize the logging behavior and how to add a custom logging provider.
Chapter 2, Customizing App Configuration, helps you understand how to use different configuration sources and add custom configuration providers.
Chapter 3, Customizing Dependency Injection, teaches you how Dependency Injection (DI) works and how to use a different DI container.
Chapter 4, Configuring and Customizing HTTPS with Kestrel, looks into configuring HTTPS differently.
Chapter 5, Configuring WebHostBuilder, helps you understand how to set up configuration on the hosting layer.
Chapter 6, Using Different Hosting Models, teaches you about different types of hosting on different platforms.
Chapter 7, Using IHostedService and BackgroundService, makes you understand how to execute tasks in the background.
Chapter 8, Writing Custom Middleware, deals with the HTTP context using middleware.
Chapter 9, Working with Endpoint Routing, helps you understand how to use the new routing to provide custom endpoints.
Chapter 10, Customizing ASP.NET Core Identity, explains how to extend the application's user properties and helps you to change the Identity UI.
Chapter 11, Configuring Identity Management, helps you to manage your users and their roles.
Chapter 12, Content Negotiation Using a Custom OutputFormatter, teaches you how to output different content types based on the HTTP Accept header.
Chapter 13, Managing Inputs with Custom ModelBinder, helps you create input models with different types of content.
Chapter 14, Creating a Custom ActionFilter, covers aspect-oriented programming using ActionFilter.
Chapter 15, Working with Caches, helps you to make your application faster.
Chapter 16, Creating Custom TagHelper, enables you to simplify the UI layer by creating TagHelper.
To get the most out of this book
Readers should have basic knowledge of ASP.NET Core and C#, as well as Visual Studio, Visual Studio Code, or any other code editor that supports ASP.NET Core and C#.
You should install the latest .NET 6.0 SDK on your machine. Please find the latest version at https://dotnet.microsoft.com/download/dotnet-core/.
Feel free to use any code editor you like that supports ASP.NET Core and C#. We recommend using Visual Studio Code (https://code.visualstudio.com/), which is available on all platforms and is used by the author of this book.
All the projects in this book will be created using a console, Command Prompt, shell, or PowerShell. Feel free to use whatever console you are comfortable with. The author uses Windows Command Prompt, hosted in the cmder shell (https://cmder.net/). We don't recommend using Visual Studio to create the projects, because the basic configuration might change, and the web projects will start on a different port than described in this book.
Are you stuck with .NET Core 3.1, or .NET 5.0? If you are not able to use .NET 6.0 on your machine for whatever reason, all the samples are also available and work with .NET Core 3.1 and .NET 5.0. Some chapters contain comparisons to .NET 5.0 whenever there are differences to .NET 6.0.
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book's GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Download the example code files
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Customizing-ASP.NET-Core-6.0-Second-Edition. If there's an update to the code, it will be updated in the GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781803233604_ColorImages.pdf.
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "You can use ConfigureAppConfiguration to configure the app configuration."
A block of code is set as...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.
File format: ePUB
Copy protection: without DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Use a reader that can handle the file format ePUB, such as Adobe Digital Editions or FBReader – both free (see eBook Help).
- Tablet/Smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePUB works well for novels and non-fiction books – i.e., 'flowing' text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook does not use copy protection or Digital Rights Management
For more information, see our eBook Help page.