ApplicationBuilder Class

Definition

Default implementation for IApplicationBuilder.

public ref class ApplicationBuilder : Microsoft::AspNetCore::Builder::IApplicationBuilder
public class ApplicationBuilder : Microsoft.AspNetCore.Builder.IApplicationBuilder
type ApplicationBuilder = class
    interface IApplicationBuilder
Public Class ApplicationBuilder
Implements IApplicationBuilder
Inheritance
ApplicationBuilder
Implements

Constructors

ApplicationBuilder(IServiceProvider)

Initializes a new instance of ApplicationBuilder.

ApplicationBuilder(IServiceProvider, Object)

Initializes a new instance of ApplicationBuilder.

Properties

ApplicationServices

Gets the IServiceProvider for application services.

Properties

Gets a set of properties for ApplicationBuilder.

ServerFeatures

Gets the IFeatureCollection for server features.

Methods

Build()

Produces a RequestDelegate that executes added middlewares.

New()

Creates a copy of this application builder.

The created clone has the same properties as the current instance, but does not copy the request pipeline.

Use(Func<RequestDelegate,RequestDelegate>)

Adds the middleware to the application request pipeline.

Extension Methods

UseAntiforgery(IApplicationBuilder)

Adds the anti-forgery middleware to the pipeline.

UseRequestLocalization(IApplicationBuilder)

Adds the RequestLocalizationMiddleware to automatically set culture information for requests based on information provided by the client.

UseRequestLocalization(IApplicationBuilder, RequestLocalizationOptions)

Adds the RequestLocalizationMiddleware to automatically set culture information for requests based on information provided by the client.

UseRequestLocalization(IApplicationBuilder, Action<RequestLocalizationOptions>)

Adds the RequestLocalizationMiddleware to automatically set culture information for requests based on information provided by the client.

UseRequestLocalization(IApplicationBuilder, String[])

Adds the RequestLocalizationMiddleware to automatically set culture information for requests based on information provided by the client.

UseAuthentication(IApplicationBuilder)

Adds the AuthenticationMiddleware to the specified IApplicationBuilder, which enables authentication capabilities.

UseAuthorization(IApplicationBuilder)

Adds the AuthorizationMiddleware to the specified IApplicationBuilder, which enables authorization capabilities.

When authorizing a resource that is routed using endpoint routing, this call must appear between the calls to app.UseRouting() and app.UseEndpoints(...) for the middleware to function correctly.

UseCertificateForwarding(IApplicationBuilder)

Adds a middleware to the pipeline that will look for a certificate in a request header decode it, and updates HttpContext.Connection.ClientCertificate.

UseBlazorFrameworkFiles(IApplicationBuilder)

Configures the application to serve Blazor WebAssembly framework files from the root path "/".

UseBlazorFrameworkFiles(IApplicationBuilder, PathString)

Configures the application to serve Blazor WebAssembly framework files from the path pathPrefix. This path must correspond to a referenced Blazor WebAssembly application project.

UseConcurrencyLimiter(IApplicationBuilder)
Obsolete.

Adds the ConcurrencyLimiterMiddleware to limit the number of concurrently-executing requests.

UseConnections(IApplicationBuilder, Action<ConnectionsRouteBuilder>)
Obsolete.

Adds support for ASP.NET Core Connection Handlers to the IApplicationBuilder request execution pipeline.

This method is obsolete and will be removed in a future version. The recommended alternative is to use MapConnections or MapConnectionHandler<TConnectionHandler> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).

UseCookiePolicy(IApplicationBuilder)

Adds the CookiePolicyMiddleware handler to the specified IApplicationBuilder, which enables cookie policy capabilities.

UseCookiePolicy(IApplicationBuilder, CookiePolicyOptions)

Adds the CookiePolicyMiddleware handler to the specified IApplicationBuilder, which enables cookie policy capabilities.

UseCors(IApplicationBuilder)

Adds a CORS middleware to your web application pipeline to allow cross domain requests.

UseCors(IApplicationBuilder, Action<CorsPolicyBuilder>)

Adds a CORS middleware to your web application pipeline to allow cross domain requests.

UseCors(IApplicationBuilder, String)

Adds a CORS middleware to your web application pipeline to allow cross domain requests.

UseDatabaseErrorPage(IApplicationBuilder)
Obsolete.

Captures synchronous and asynchronous database related exceptions from the pipeline that may be resolved using Entity Framework migrations. When these exceptions occur, an HTML response with details of possible actions to resolve the issue is generated.

UseDatabaseErrorPage(IApplicationBuilder, DatabaseErrorPageOptions)
Obsolete.

Captures synchronous and asynchronous database related exceptions from the pipeline that may be resolved using Entity Framework migrations. When these exceptions occur, an HTML response with details of possible actions to resolve the issue is generated.

UseDefaultFiles(IApplicationBuilder)

Enables default file mapping on the current path

UseDefaultFiles(IApplicationBuilder, DefaultFilesOptions)

Enables default file mapping with the given options

UseDefaultFiles(IApplicationBuilder, String)

Enables default file mapping for the given request path

UseDeveloperExceptionPage(IApplicationBuilder)

Captures synchronous and asynchronous Exception instances from the pipeline and generates HTML error responses.

UseDeveloperExceptionPage(IApplicationBuilder, DeveloperExceptionPageOptions)

Captures synchronous and asynchronous Exception instances from the pipeline and generates HTML error responses.

UseDirectoryBrowser(IApplicationBuilder)

Enable directory browsing on the current path

UseDirectoryBrowser(IApplicationBuilder, DirectoryBrowserOptions)

Enable directory browsing with the given options

UseDirectoryBrowser(IApplicationBuilder, String)

Enables directory browsing for the given request path

UseEndpoints(IApplicationBuilder, Action<IEndpointRouteBuilder>)

Adds a Microsoft.AspNetCore.Routing.EndpointMiddleware middleware to the specified IApplicationBuilder with the EndpointDataSource instances built from configured IEndpointRouteBuilder. The Microsoft.AspNetCore.Routing.EndpointMiddleware will execute the Endpoint associated with the current request.

UseRouting(IApplicationBuilder)

Adds a Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware middleware to the specified IApplicationBuilder.

UseExceptionHandler(IApplicationBuilder)

Adds a middleware to the pipeline that will catch exceptions, log them, and re-execute the request in an alternate pipeline. The request will not be re-executed if the response has already started.

UseExceptionHandler(IApplicationBuilder, ExceptionHandlerOptions)

Adds a middleware to the pipeline that will catch exceptions, log them, and re-execute the request in an alternate pipeline. The request will not be re-executed if the response has already started.

UseExceptionHandler(IApplicationBuilder, Action<IApplicationBuilder>)

Adds a middleware to the pipeline that will catch exceptions, log them, and re-execute the request in an alternate pipeline. The request will not be re-executed if the response has already started.

UseExceptionHandler(IApplicationBuilder, String)

Adds a middleware to the pipeline that will catch exceptions, log them, reset the request path, and re-execute the request. The request will not be re-executed if the response has already started.

UseExceptionHandler(IApplicationBuilder, String, Boolean)

Adds a middleware to the pipeline that will catch exceptions, log them, reset the request path, and re-execute the request. The request will not be re-executed if the response has already started.

UseFileServer(IApplicationBuilder)

Enable all static file middleware (except directory browsing) for the current request path in the current directory.

UseFileServer(IApplicationBuilder, FileServerOptions)

Enable all static file middleware with the given options

UseFileServer(IApplicationBuilder, Boolean)

Enable all static file middleware on for the current request path in the current directory.

UseFileServer(IApplicationBuilder, String)

Enables all static file middleware (except directory browsing) for the given request path from the directory of the same name

UseForwardedHeaders(IApplicationBuilder)

Applies forwarded headers to their matching fields on the current request.

By convention, HTTP proxies forward information from the client in well-known HTTP headers. The ForwardedHeadersMiddleware reads these headers and fills in the associated fields on HttpContext.

UseForwardedHeaders(IApplicationBuilder, ForwardedHeadersOptions)

Applies forwarded headers to their matching fields on the current request.

By convention, HTTP proxies forward information from the client in well-known HTTP headers. The ForwardedHeadersMiddleware reads these headers and fills in the associated fields on HttpContext.

UseHeaderPropagation(IApplicationBuilder)

Adds a middleware that collect headers to be propagated to a HttpClient.

UseHealthChecks(IApplicationBuilder, PathString)

Adds a middleware that provides health check status.

UseHealthChecks(IApplicationBuilder, PathString, HealthCheckOptions)

Adds a middleware that provides health check status.

UseHealthChecks(IApplicationBuilder, PathString, Int32)

Adds a middleware that provides health check status.

UseHealthChecks(IApplicationBuilder, PathString, Int32, HealthCheckOptions)

Adds a middleware that provides health check status.

UseHealthChecks(IApplicationBuilder, PathString, String)

Adds a middleware that provides health check status.

UseHealthChecks(IApplicationBuilder, PathString, String, HealthCheckOptions)

Adds a middleware that provides health check status.

UseHostFiltering(IApplicationBuilder)

Adds middleware for filtering requests by allowed host headers. Invalid requests will be rejected with a 400 status code.

UseHsts(IApplicationBuilder)

Adds middleware for using HSTS, which adds the Strict-Transport-Security header.

UseHttpLogging(IApplicationBuilder)

Adds a middleware that can log HTTP requests and responses.

UseW3CLogging(IApplicationBuilder)

Adds a middleware that can log HTTP requests and responses for server logs in W3C format.

UseHttpMethodOverride(IApplicationBuilder)

Allows incoming POST request to override method type with type specified in header. This middleware is used when a client is limited to sending GET or POST methods but wants to invoke other HTTP methods. By default, the X-HTTP-Method-Override request header is used to specify the HTTP method being tunneled.

UseHttpMethodOverride(IApplicationBuilder, HttpMethodOverrideOptions)

Allows incoming POST request to override method type with type specified in form. This middleware is used when a client is limited to sending GET or POST methods but wants to invoke other HTTP methods.

UseHttpsRedirection(IApplicationBuilder)

Adds middleware for redirecting HTTP Requests to HTTPS.

Map(IApplicationBuilder, PathString, Action<IApplicationBuilder>)

Branches the request pipeline based on matches of the given request path. If the request path starts with the given path, the branch is executed.

Map(IApplicationBuilder, PathString, Boolean, Action<IApplicationBuilder>)

Branches the request pipeline based on matches of the given request path. If the request path starts with the given path, the branch is executed.

Map(IApplicationBuilder, String, Action<IApplicationBuilder>)

Branches the request pipeline based on matches of the given request path. If the request path starts with the given path, the branch is executed.

MapWhen(IApplicationBuilder, Func<HttpContext,Boolean>, Action<IApplicationBuilder>)

Branches the request pipeline based on the result of the given predicate.

UseMigrationsEndPoint(IApplicationBuilder)

Processes requests to execute migrations operations. The middleware will listen for requests made to DefaultPath.

UseMigrationsEndPoint(IApplicationBuilder, MigrationsEndPointOptions)

Processes requests to execute migrations operations. The middleware will listen for requests to the path configured in options.

UseMvc(IApplicationBuilder)

Adds MVC to the IApplicationBuilder request execution pipeline.

UseMvc(IApplicationBuilder, Action<IRouteBuilder>)

Adds MVC to the IApplicationBuilder request execution pipeline.

UseMvcWithDefaultRoute(IApplicationBuilder)

Adds MVC to the IApplicationBuilder request execution pipeline with a default route named 'default' and the following template: '{controller=Home}/{action=Index}/{id?}'.

UseOutputCache(IApplicationBuilder)
UseOwin(IApplicationBuilder)

Adds an OWIN pipeline to the specified IApplicationBuilder.

UseOwin(IApplicationBuilder, Action<Action<Func<Func<IDictionary<String,Object>,Task>,Func<IDictionary<String,Object>,Task>>>>)

Adds OWIN middleware pipeline to the specified IApplicationBuilder.

UseRateLimiter(IApplicationBuilder)

Enables rate limiting for the application.

UseRateLimiter(IApplicationBuilder, RateLimiterOptions)

Enables rate limiting for the application.

UseRequestDecompression(IApplicationBuilder)

Adds middleware for dynamically decompressing HTTP request bodies.

UseRequestTimeouts(IApplicationBuilder)

Enables request timeouts for the application.

No timeouts are configured by default. They must be configured in RequestTimeoutOptions, the RequestTimeoutAttribute on endpoints, or using the WithRequestTimeout routing extensions.

UseResponseCaching(IApplicationBuilder)

Adds the ResponseCachingMiddleware for caching HTTP responses.

UseResponseCompression(IApplicationBuilder)

Adds middleware for dynamically compressing HTTP Responses.

UseRewriter(IApplicationBuilder)

Checks if a given Url matches rules and conditions, and modifies the HttpContext on match.

UseRewriter(IApplicationBuilder, RewriteOptions)

Checks if a given Url matches rules and conditions, and modifies the HttpContext on match.

UseRouter(IApplicationBuilder, IRouter)

Adds a RouterMiddleware middleware to the specified IApplicationBuilder with the specified IRouter.

UseRouter(IApplicationBuilder, Action<IRouteBuilder>)

Adds a RouterMiddleware middleware to the specified IApplicationBuilder with the IRouter built from configured IRouteBuilder.

Run(IApplicationBuilder, RequestDelegate)

Adds a terminal middleware delegate to the application's request pipeline.

UseSession(IApplicationBuilder)

Adds the SessionMiddleware to automatically enable session state for the application.

UseSession(IApplicationBuilder, SessionOptions)

Adds the SessionMiddleware to automatically enable session state for the application.

UseSignalR(IApplicationBuilder, Action<HubRouteBuilder>)
Obsolete.

Adds SignalR to the IApplicationBuilder request execution pipeline.

This method is obsolete and will be removed in a future version. The recommended alternative is to use MapHub<THub> inside Microsoft.AspNetCore.Builder.UseEndpoints(...).

UseSpa(IApplicationBuilder, Action<ISpaBuilder>)

Handles all requests from this point in the middleware chain by returning the default page for the Single Page Application (SPA).

This middleware should be placed late in the chain, so that other middleware for serving static files, MVC actions, etc., takes precedence.

UseStaticFiles(IApplicationBuilder)

Enables static file serving for the current request path

UseStaticFiles(IApplicationBuilder, StaticFileOptions)

Enables static file serving with the given options

UseStaticFiles(IApplicationBuilder, String)

Enables static file serving for the given request path

UseStatusCodePages(IApplicationBuilder)

Adds a StatusCodePages middleware with a default response handler that checks for responses with status codes between 400 and 599 that do not have a body.

UseStatusCodePages(IApplicationBuilder, StatusCodePagesOptions)

Adds a StatusCodePages middleware with the given options that checks for responses with status codes between 400 and 599 that do not have a body.

UseStatusCodePages(IApplicationBuilder, Action<IApplicationBuilder>)

Adds a StatusCodePages middleware to the pipeline with the specified alternate middleware pipeline to execute to generate the response body.

UseStatusCodePages(IApplicationBuilder, Func<StatusCodeContext,Task>)

Adds a StatusCodePages middleware with the specified handler that checks for responses with status codes between 400 and 599 that do not have a body.

UseStatusCodePages(IApplicationBuilder, String, String)

Adds a StatusCodePages middleware with the specified response body to send. This may include a '{0}' placeholder for the status code. The middleware checks for responses with status codes between 400 and 599 that do not have a body.

UseStatusCodePagesWithRedirects(IApplicationBuilder, String)

Adds a StatusCodePages middleware to the pipeline. Specifies that responses should be handled by redirecting with the given location URL template. This may include a '{0}' placeholder for the status code. URLs starting with '~' will have PathBase prepended, where any other URL will be used as is.

UseStatusCodePagesWithReExecute(IApplicationBuilder, String, String)

Adds a StatusCodePages middleware to the pipeline. Specifies that the response body should be generated by re-executing the request pipeline using an alternate path. This path may contain a '{0}' placeholder of the status code.

Use(IApplicationBuilder, Func<HttpContext,RequestDelegate,Task>)

Adds a middleware delegate defined in-line to the application's request pipeline. If you aren't calling the next function, use Run(IApplicationBuilder, RequestDelegate) instead.

Use(IApplicationBuilder, Func<HttpContext,Func<Task>,Task>)

Adds a middleware delegate defined in-line to the application's request pipeline. If you aren't calling the next function, use Run(IApplicationBuilder, RequestDelegate) instead.

Prefer using Use(IApplicationBuilder, Func<HttpContext,RequestDelegate,Task>) for better performance as shown below:

app.Use((context, next) =>
{
    return next(context);
});
UseMiddleware(IApplicationBuilder, Type, Object[])

Adds a middleware type to the application's request pipeline.

UseMiddleware<TMiddleware>(IApplicationBuilder, Object[])

Adds a middleware type to the application's request pipeline.

UsePathBase(IApplicationBuilder, PathString)

Adds a middleware that extracts the specified path base from request path and postpend it to the request path base.

UseWhen(IApplicationBuilder, Func<HttpContext,Boolean>, Action<IApplicationBuilder>)

Conditionally creates a branch in the request pipeline that is rejoined to the main pipeline.

UseWebAssemblyDebugging(IApplicationBuilder)

Adds middleware needed for debugging Blazor WebAssembly applications inside Chromium dev tools.

UseWebpackDevMiddleware(IApplicationBuilder, WebpackDevMiddlewareOptions)
Obsolete.

Enables Webpack dev middleware support. This hosts an instance of the Webpack compiler in memory in your application so that you can always serve up-to-date Webpack-built resources without having to run the compiler manually. Since the Webpack compiler instance is retained in memory, incremental compilation is vastly faster that re-running the compiler from scratch.

Incoming requests that match Webpack-built files will be handled by returning the Webpack compiler output directly, regardless of files on disk. If compilation is in progress when the request arrives, the response will pause until updated compiler output is ready.

UseWebSockets(IApplicationBuilder)

Adds the WebSocketMiddleware to the request pipeline.

UseWebSockets(IApplicationBuilder, WebSocketOptions)

Adds the WebSocketMiddleware to the request pipeline.

UseWelcomePage(IApplicationBuilder)

Adds the WelcomePageMiddleware to the pipeline.

UseWelcomePage(IApplicationBuilder, WelcomePageOptions)

Adds the WelcomePageMiddleware to the pipeline with the given options.

UseWelcomePage(IApplicationBuilder, PathString)

Adds the WelcomePageMiddleware to the pipeline with the given path.

UseWelcomePage(IApplicationBuilder, String)

Adds the WelcomePageMiddleware to the pipeline with the given path.

UseHttpLoggingMiddleware(IApplicationBuilder)

Registers incoming HTTP request logging middleware into IApplicationBuilder.

UseRequestCheckpoint(IApplicationBuilder)

Registers Request Checkpoint related middlewares into the pipeline.

UseRequestLatencyTelemetry(IApplicationBuilder)

Adds the request latency telemetry middleware to IApplicationBuilder request execution pipeline.

UseSpaStaticFiles(IApplicationBuilder)

Configures the application to serve static files for a Single Page Application (SPA). The files will be located using the registered ISpaStaticFileProvider service.

UseSpaStaticFiles(IApplicationBuilder, StaticFileOptions)

Configures the application to serve static files for a Single Page Application (SPA). The files will be located using the registered ISpaStaticFileProvider service.

Applies to