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

