Customizing ASP.NET Core 5.0 by Jürgen Gutsch

Customizing ASP.NET Core 5.0 by Jürgen Gutsch

Author:Jürgen Gutsch
Language: eng
Format: epub
Publisher: Packt Publishing Pvt. Ltd.
Published: 2021-01-28T00:00:00+00:00


Rewriting a terminating middleware to current standards

If you have an existing middleware that provides a different endpoint, you should change it to use the new endpoint routing:

As an example, let's create a small dummy middleware that writes an application status to a specific route. In this demo, there is no custom route handling:public class AppStatusMiddleware

{

private readonly RequestDelegate _next;

private readonly string _status;

public AppStatusMiddleware(

RequestDelegate next, string status)

{

_next = next;

_status = status;

}

public async Task Invoke(HttpContext context)

{

await context.Response.WriteAsync(

$"Hello {_status}!");

}

}

The first thing we need to do is to write an extension method on the IEndpointRouteBuilder type. This method has a route pattern as an optional argument and returns an IEndpointConventionBuilder type to enable CORS, authentication, or other conditions to the route.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.