Customizing ASP.NET Core 5.0
eBook - ePub

Customizing ASP.NET Core 5.0

Turn the right screws in ASP.NET Core to get the most out of the framework

  1. 160 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Customizing ASP.NET Core 5.0

Turn the right screws in ASP.NET Core to get the most out of the framework

About this book

A guide to discovering the hidden behaviors of ASP.NET Core that can be customized to optimize your.NET 5 applications

Key Features

  • Customize the default behavior of ASP.NET Core to get the most out of the framework
  • Enhance the app configuration, change the default dependency injection, and build your own tag helpers
  • Discover best practices for configuring ASP.NET Core, from user interface design to hosting it on platforms

Book Description

ASP.NET Core is the most powerful Microsoft web framework. Although it's full of rich features, sometimes the default configurations can be a bottleneck and need to be customized to suit the nature and scale of your app. If you're an intermediate-level.NET developer who wants to extend.NET Core to multiple use cases, it's important to customize these features so that the framework works for you effectively.

Customizing ASP.NET Core 5.0 covers core features that can be customized for developing optimized apps. The customization techniques are also updated to work with the latest.NET 5 framework.

You'll learn essential concepts relating to optimizing 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 application development book, you'll have the skills you need to be able to customize ASP.NET Core to develop robust optimized apps.

What you will learn

  • Explore various application configurations and providers in ASP.NET Core 5
  • Understand dependency injection in.NET and learn how to add third-party DI containers
  • Discover the concept of middleware and write your own 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
  • Develop custom routing endpoints and add third-party endpoints
  • Configure WebHostBuilder effectively for your web applications

Who this book is for

This.NET 5 book is for.NET developers who need to change the default behaviors of the framework to help improve the performance of their applications. Intermediate-level knowledge of ASP.NET Core and C# is required before getting started with the book.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Customizing ASP.NET Core 5.0 by Jürgen Gutsch in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in C#. We have over one million books available in our catalogue for you to explore.

Information

Chapter 1: Customizing Logging

In this first chapter of the book about customizing ASP.NET Core, you will see how to customize logging. The default logging only writes to the console or to the debug window. This is quite good for the majority of cases, but it may be the case that you need to log to a sink, such as a file or a database. Perhaps you want to extend the logger with additional information. In these cases, you need to know how to change the default logging.
In this chapter, we will be covering the following topics:
  • Configuring logging
  • Creating a custom logger
  • Plugging in an existing third-party logger provider
The topics in this chapter refer to the hosting layer of the ASP.NET Core architecture:
Figure 1.1 – ASP.NET Core architecture
Figure 1.1 – ASP.NET Core architecture

Technical requirements

To follow the descriptions in this chapter, you will need to create an ASP.NET Core MVC application. Open your console, shell, or bash terminal, and change to your working directory. Use the following command to create a new MVC application:
dotnet new mvc -n LoggingSample -o LoggingSample
Now, open the project in Visual Studio by double-clicking the project file or, in VS Code, by typing the following command in the already open console:
cd LoggingSample
code.
All of the code samples in this chapter can be found in the GitHub repository for this book at https://github.com/PacktPublishing/Customizing-ASP.NET-Core-5.0/tree/main/Chapter01.

Configuring logging

In previous versions of ASP.NET Core (pre-2.0), logging was configured in Startup.cs. As a reminder, since version 2.0, the Startup.cs file has been simplified, and a lot of configurations were moved to default WebHostBuilder, which is called in Program.cs. Also, logging was moved to default WebHostBuilder.
In ASP.NET Core 3.1 and later versions, the Program.cs file gets more generic, and IHostBuilder will be created first. IHostBuilder is pretty useful for bootstrapping an application without all the ASP.NET web stuff. We'll learn a lot more about IHostBuilder later on in the following chapters. With this IHostBuilder, we create IWebHostBuilder to configure ASP.NET Core. In ASP.NET Core 3.1 and later versions, we get IWebHostBuilder with the webBuilder variable:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[]
args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
In ASP.NET Core, you are able to override and customize almost everything. This includes logging. ...

Table of contents

  1. Customizing ASP.NET Core 5.0
  2. Why subscribe?
  3. Preface
  4. Chapter 1: Customizing Logging
  5. Chapter 2: Customizing App Configuration
  6. Chapter 3: Customizing Dependency Injection
  7. Chapter 4: Configuring and Customizing HTTPS with Kestrel
  8. Chapter 5: Using IHostedService and BackgroundService
  9. Chapter 6: Writing Custom Middleware
  10. Chapter 7: Content Negotiation Using a Custom OutputFormatter
  11. Chapter 8: Managing Inputs with Custom ModelBinders
  12. Chapter 9: Creating a Custom ActionFilter
  13. Chapter 10: Creating Custom TagHelpers
  14. Chapter 11: Configuring WebHostBuilder
  15. Chapter 12: Using Different Hosting Models
  16. Chapter 13: Working with Endpoint Routing
  17. Other Books You May Enjoy