liveBook · Manning

UseEndpoints

As explained in ASP.NET Core in Action, 3e

UseEndpoints is an ASP.NET Core extension method that adds endpoint execution middleware and registers endpoints in a request pipeline.

UseEndpoints is an ASP.NET Core middleware extension for Startup-based applications. It adds endpoint execution middleware and provides an IEndpointRouteBuilder for registering the application's endpoints. section 30.3 section 30.7

Configure UseEndpoints at the end of the request pipeline, after routing, authentication, and authorization:

  • Call app.UseRouting() before endpoint registration. section 30.3
  • Call app.UseAuthentication() and app.UseAuthorization() when the application requires them. section 30.3
  • Pass a lambda to UseEndpoints and call the appropriate Map* method on endpoints. section 30.7
  • Keep UseEndpoints near the end of Configure; middleware order determines request-pipeline order. section 30.3 section 30.7

Register Razor Pages in Startup

public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); } section 30.3

Listing 30.4 Startup.Configure() for a Razor Pages application
public class Startup
{
    public void Configure(
        IApplicationBuilder app,              #1
        IWebHostEnvironment env)              #2
    {
        if (env.IsDevelopment())              #3
        {
            app.UseDeveloperExceptionPage();  #4
        }
        else
        {
            app.UseExceptionHandler("/Error");
            app.UseHsts();
        }
 
        app.UseHttpsRedirection();
        app.UseStaticFiles();
 
        app.UseRouting();                     #5
 
        app.UseAuthentication();  
        app.UseAuthorization();               #6
 
        app.UseEndpoints(endpoints =>         #7
        {
            endpoints.MapRazorPages();        #8
        });
    }
}

Use the complete Startup.Configure listing to inspect environment-specific error handling, HTTPS redirection, static files, routing, authorization, and endpoint mapping together. section 30.3

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains middleware placement and Map* registration, but does not descend into endpoint execution internals.
Examples
Demonstrates a Startup.Configure pipeline that maps Razor Pages with endpoints.MapRazorPages().
What it assumes
Assumes familiarity with Startup.Configure and middleware, while showing the required routing and endpoint setup explicitly.
What you can do after
Operate/configure an ASP.NET Core Startup pipeline and register Razor Pages or other endpoints through Map* methods.
How it connects
Connects endpoint routing with middleware, Startup, IApplicationBuilder, IEndpointRouteBuilder, Razor Pages, and WebApplication.

Also explained in

Compare how 2 books explain UseEndpoints →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.