E-Book, Englisch, 204 Seiten
Gutsch Customizing ASP.NET Core 6.0
2. Auflage 2024
ISBN: 978-1-80324-381-8
Verlag: De Gruyter
Format: EPUB
Kopierschutz: 0 - No protection
Learn to turn the right screws to optimize ASP.NET Core applications for better performance
E-Book, Englisch, 204 Seiten
ISBN: 978-1-80324-381-8
Verlag: De Gruyter
Format: EPUB
Kopierschutz: 0 - No protection
ASP.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.
Autoren/Hrsg.
Fachgebiete
Weitere Infos & Material
Table of Contents - 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
, , teaches you how to customize the logging behavior and how to add a custom logging provider.
, , helps you understand how to use different configuration sources and add custom configuration providers.
, , teaches you how Dependency Injection (DI) works and how to use a different DI container.
, , looks into configuring HTTPS differently.
, , helps you understand how to set up configuration on the hosting layer.
, , teaches you about different types of hosting on different platforms.
, , makes you understand how to execute tasks in the background.
, , deals with the HTTP context using middleware.
, , helps you understand how to use the new routing to provide custom endpoints.
, , explains how to extend the application's user properties and helps you to change the Identity UI.
, , helps you to manage your users and their roles.
, , teaches you how to output different content types based on the HTTP Accept header.
, , helps you create input models with different types of content.
, , covers aspect-oriented programming using ActionFilter.
, , helps you to make your application faster.
, , 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...




