Customizing ASP.NET Core 6.0
eBook - ePub

Customizing ASP.NET Core 6.0

Learn to turn the right screws to optimize ASP.NET Core applications for better performance, 2nd Edition

Jürgen Gutsch

  1. 202 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Customizing ASP.NET Core 6.0

Learn to turn the right screws to optimize ASP.NET Core applications for better performance, 2nd Edition

Jürgen Gutsch

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

Explore hidden behaviors and customization techniques to help you get the most out of ASP.NET Core for building web applications

Key Features

  • Second edition updated and enhanced to cover the latest.NET 6 features and changes
  • Learn expert techniques to implement authentication and authorization for securing your web apps
  • Discover best practices for configuring ASP.NET Core, from user interface design to hosting it on platforms

Book Description

ASP.NET Core comes packed full of hidden features for building sophisticated web applications. You'd be missing out on a lot of its capabilities by not customizing it to work for your applications. With Customizing ASP.NET Core 6.0, you'll discover techniques to help you get the most out of the framework to deliver robust applications.

In this updated second edition, you'll cover the latest features and changes in the.NET 6 LTS version. You'll find new insights and customization techniques for important topics such as authentication and authorization. The book will also show you how to work with caches and change the default behavior of ASP.NET Core apps. 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 book, you'll 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 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 for

This.NET 6 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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Customizing ASP.NET Core 6.0 un PDF/ePUB en línea?
Sí, puedes acceder a Customizing ASP.NET Core 6.0 de Jürgen Gutsch en formato PDF o ePUB, así como a otros libros populares de Ciencia de la computación y Programación en C#. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2021
ISBN
9781803243818

Chapter 1: Customizing Logging

In this chapter, the first in this book about customizing ASP.NET Core, you will see how to customize logging. The default logging only writes to the console or the debug window. This is quite good for the majority of cases, but sometimes you need to log to a sink, such as a file or a database. Or, 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 – The ASP.NET Core architecture
Figure 1.1 – The ASP.NET Core architecture

Technical requirements

To follow the descriptions in this chapter, you will need to create an ASP.NET Core MVC application. To do this, open your console, shell, or Bash terminal, and change to your working directory. Then, use the following command to create a new MVC application:
dotnet new mvc -n LoggingSample -o LoggingSample
Now, open the project in Microsoft Visual Studio by double-clicking the project file, or in Visual Studio 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-6.0-Second-Edition/tree/main/Chapter01.

Configuring logging

In previous versions of ASP.NET Core (that is, before version 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 have been moved to the default WebHostBuilder, which is called in Program.cs. Also, logging was moved to the 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 of the ASP.NET web stuff. We'll learn a lot more about IHostBuilder later on in this book. 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 6.0, Microsoft introduced the minimal API approach that simplifies the configuration a lot. This approach doesn't use the Startup file and adds all of the configurations to the Program.cs file instead. Let's see what this looks like:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// The rest of the file isn't relevant for this chapter
In ASP.NET Core, you are able to override and customize almost everything. This includes logging. IWebHostBuilder has a lot of extension methods that allow us to override the default behavior of different features. To override the default settings for logging, we need to use the ConfigureLogging method. The following code snippet shows almost exactly the same logging as was configured inside the ConfigureWebHostDefaults() method:
Host.Cre...

Índice

Estilos de citas para Customizing ASP.NET Core 6.0

APA 6 Citation

Gutsch, J. (2021). Customizing ASP.NET Core 6.0 (2nd ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/3183430/customizing-aspnet-core-60-learn-to-turn-the-right-screws-to-optimize-aspnet-core-applications-for-better-performance-2nd-edition-pdf (Original work published 2021)

Chicago Citation

Gutsch, Jürgen. (2021) 2021. Customizing ASP.NET Core 6.0. 2nd ed. Packt Publishing. https://www.perlego.com/book/3183430/customizing-aspnet-core-60-learn-to-turn-the-right-screws-to-optimize-aspnet-core-applications-for-better-performance-2nd-edition-pdf.

Harvard Citation

Gutsch, J. (2021) Customizing ASP.NET Core 6.0. 2nd edn. Packt Publishing. Available at: https://www.perlego.com/book/3183430/customizing-aspnet-core-60-learn-to-turn-the-right-screws-to-optimize-aspnet-core-applications-for-better-performance-2nd-edition-pdf (Accessed: 15 October 2022).

MLA 7 Citation

Gutsch, Jürgen. Customizing ASP.NET Core 6.0. 2nd ed. Packt Publishing, 2021. Web. 15 Oct. 2022.