WebApplication 类

定义

用于配置 HTTP 管道和路由的 Web 应用程序。

public sealed class WebApplication : IAsyncDisposable, IDisposable, Microsoft.AspNetCore.Builder.IApplicationBuilder, Microsoft.AspNetCore.Routing.IEndpointRouteBuilder, Microsoft.Extensions.Hosting.IHost
type WebApplication = class
    interface IHost
    interface IDisposable
    interface IApplicationBuilder
    interface IEndpointRouteBuilder
    interface IAsyncDisposable
Public NotInheritable Class WebApplication
Implements IApplicationBuilder, IAsyncDisposable, IDisposable, IEndpointRouteBuilder, IHost
继承
WebApplication
实现

属性

Configuration

应用程序配置的 IConfiguration

Environment

应用程序配置的 IWebHostEnvironment

Lifetime

允许通知使用者应用程序生存期事件。

Logger

应用程序的默认记录器。

Services

应用程序配置的服务。

Urls

HTTP 服务器绑定到的 URL 列表。

方法

Create(String[])

使用预配置的默认值初始化 类的新实例 WebApplication

CreateBuilder()

使用预配置的默认值初始化 类的新实例 WebApplicationBuilder

CreateBuilder(String[])

使用预配置的默认值初始化 类的新实例 WebApplicationBuilder

CreateBuilder(WebApplicationOptions)

使用预配置的默认值初始化 类的新实例 WebApplicationBuilder

CreateEmptyBuilder(WebApplicationOptions)

初始化 没有默认值的 WebApplicationBuilder 类的新实例。

CreateSlimBuilder()

使用最少的 WebApplicationBuilder 默认值初始化 类的新实例。

CreateSlimBuilder(String[])

使用最少的 WebApplicationBuilder 默认值初始化 类的新实例。

CreateSlimBuilder(WebApplicationOptions)

使用最少的 WebApplicationBuilder 默认值初始化 类的新实例。

DisposeAsync()

释放应用程序。

Run(String)

运行应用程序并阻止调用线程,直至主机关闭。

RunAsync(String)

运行应用程序,并返回仅在触发了令牌或触发了关闭时才完成的任务。

StartAsync(CancellationToken)

启动应用程序。

StopAsync(CancellationToken)

关闭应用程序。

Use(Func<RequestDelegate,RequestDelegate>)

将中间件添加到应用程序请求管道。

显式接口实现

IApplicationBuilder.ApplicationServices

用于配置 HTTP 管道和路由的 Web 应用程序。

IApplicationBuilder.Build()

用于配置 HTTP 管道和路由的 Web 应用程序。

IApplicationBuilder.New()

用于配置 HTTP 管道和路由的 Web 应用程序。

IApplicationBuilder.Properties

用于配置 HTTP 管道和路由的 Web 应用程序。

IApplicationBuilder.ServerFeatures

用于配置 HTTP 管道和路由的 Web 应用程序。

IApplicationBuilder.Use(Func<RequestDelegate,RequestDelegate>)

用于配置 HTTP 管道和路由的 Web 应用程序。

IDisposable.Dispose()

释放应用程序。

IEndpointRouteBuilder.CreateApplicationBuilder()

用于配置 HTTP 管道和路由的 Web 应用程序。

IEndpointRouteBuilder.DataSources

用于配置 HTTP 管道和路由的 Web 应用程序。

IEndpointRouteBuilder.ServiceProvider

用于配置 HTTP 管道和路由的 Web 应用程序。

扩展方法

UseAntiforgery(IApplicationBuilder)

将防伪中间件添加到管道。

UseRequestLocalization(IApplicationBuilder)

添加 以 RequestLocalizationMiddleware 根据客户端提供的信息自动设置请求的区域性信息。

UseRequestLocalization(IApplicationBuilder, RequestLocalizationOptions)

添加 以 RequestLocalizationMiddleware 根据客户端提供的信息自动设置请求的区域性信息。

UseRequestLocalization(IApplicationBuilder, Action<RequestLocalizationOptions>)

添加 以 RequestLocalizationMiddleware 根据客户端提供的信息自动设置请求的区域性信息。

UseRequestLocalization(IApplicationBuilder, String[])

添加 以 RequestLocalizationMiddleware 根据客户端提供的信息自动设置请求的区域性信息。

UseAuthentication(IApplicationBuilder)

AuthenticationMiddleware将 添加到指定的 IApplicationBuilder中,这将启用身份验证功能。

UseAuthorization(IApplicationBuilder)

AuthorizationMiddleware将 添加到指定的 IApplicationBuilder中,这将启用授权功能。

当授权使用终结点路由路由的资源时,此调用必须在调用 app.UseRouting()app.UseEndpoints(...) 之间出现,中间件才能正常运行。

UseCertificateForwarding(IApplicationBuilder)

将中间件添加到管道中,该中间件将在请求标头中查找证书解码,并更新 HttpContext.Connection.ClientCertificate。

MapBlazorHub(IEndpointRouteBuilder)

将 Blazor Hub 映射到默认路径。

MapBlazorHub(IEndpointRouteBuilder, Action<HttpConnectionDispatcherOptions>)

将 Blazor Hub 映射到默认路径。

MapBlazorHub(IEndpointRouteBuilder, String)

将 Blazor Hub 映射到路径 path

MapBlazorHub(IEndpointRouteBuilder, String, Action<HttpConnectionDispatcherOptions>)

将 Blazor Hub 映射到路径 path

UseBlazorFrameworkFiles(IApplicationBuilder)

将应用程序配置为从根路径“/”提供 Blazor WebAssembly 框架文件。

UseBlazorFrameworkFiles(IApplicationBuilder, PathString)

将应用程序配置为从路径 pathPrefix提供 Blazor WebAssembly 框架文件。 此路径必须对应于引用的 Blazor WebAssembly 应用程序项目。

UseConcurrencyLimiter(IApplicationBuilder)
已过时.

添加 以 ConcurrencyLimiterMiddleware 限制并发执行的请求数。

MapConnectionHandler<TConnectionHandler>(IEndpointRouteBuilder, String)

将具有指定路径的传入请求映射到所提供的连接管道。

MapConnectionHandler<TConnectionHandler>(IEndpointRouteBuilder, String, Action<HttpConnectionDispatcherOptions>)

将具有指定路径的传入请求映射到所提供的连接管道。

MapConnections(IEndpointRouteBuilder, String, HttpConnectionDispatcherOptions, Action<IConnectionBuilder>)

将具有指定路径的传入请求映射到所提供的连接管道。

MapConnections(IEndpointRouteBuilder, String, Action<IConnectionBuilder>)

将具有指定路径的传入请求映射到所提供的连接管道。

MapAreaControllerRoute(IEndpointRouteBuilder, String, String, String, Object, Object, Object)

将控制器操作的终结点添加到 ,IEndpointRouteBuilder并指定具有给定 name、、areaNamepatterndefaultsconstraintsdataTokens的路由。

MapControllerRoute(IEndpointRouteBuilder, String, String, Object, Object, Object)

将控制器操作的终结点添加到 ,IEndpointRouteBuilder并使用给定name的 、pattern、、 defaultsconstraintsdataTokens指定路由。

MapControllers(IEndpointRouteBuilder)

在未指定任何路由的情况下, IEndpointRouteBuilder 将控制器操作的终结点添加到 。

MapDefaultControllerRoute(IEndpointRouteBuilder)

将控制器操作的终结点添加到 , IEndpointRouteBuilder 并添加默认路由 {controller=Home}/{action=Index}/{id?}

MapDynamicControllerRoute<TTransformer>(IEndpointRouteBuilder, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将尝试使用 生成的 TTransformer路由值选择控制器操作。

MapDynamicControllerRoute<TTransformer>(IEndpointRouteBuilder, String, Object)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将尝试使用 生成的 TTransformer路由值选择控制器操作。

MapDynamicControllerRoute<TTransformer>(IEndpointRouteBuilder, String, Object, Int32)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将尝试使用 生成的 TTransformer路由值选择控制器操作。

MapFallbackToAreaController(IEndpointRouteBuilder, String, String, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。 请求将路由到与 、 controllerarea匹配的action控制器终结点。

MapFallbackToAreaController(IEndpointRouteBuilder, String, String, String, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。 请求将路由到与 、 controllerarea匹配的action控制器终结点。

MapFallbackToController(IEndpointRouteBuilder, String, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。 请求将路由到与 、 和 controller匹配的action控制器终结点。

MapFallbackToController(IEndpointRouteBuilder, String, String, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。 请求将路由到与 、 和 controller匹配的action控制器终结点。

UseCookiePolicy(IApplicationBuilder)

CookiePolicyMiddleware 处理程序添加到指定的 IApplicationBuilder中,这将启用 Cookie 策略功能。

UseCookiePolicy(IApplicationBuilder, CookiePolicyOptions)

CookiePolicyMiddleware 处理程序添加到指定的 IApplicationBuilder中,这将启用 Cookie 策略功能。

UseCors(IApplicationBuilder)

将 CORS 中间件添加到你的 Web 应用程序管道,以允许跨域请求。

UseCors(IApplicationBuilder, Action<CorsPolicyBuilder>)

将 CORS 中间件添加到你的 Web 应用程序管道,以允许跨域请求。

UseCors(IApplicationBuilder, String)

将 CORS 中间件添加到你的 Web 应用程序管道,以允许跨域请求。

UseDatabaseErrorPage(IApplicationBuilder)
已过时.

从管道中捕获可以使用实体框架迁移解决的同步和异步数据库相关异常。 当这些异常出现时,便会生成 HTML 响应,其中包含用于解决问题的可能操作的详细信息。

UseDatabaseErrorPage(IApplicationBuilder, DatabaseErrorPageOptions)
已过时.

从管道中捕获可以使用实体框架迁移解决的同步和异步数据库相关异常。 当这些异常出现时,便会生成 HTML 响应,其中包含用于解决问题的可能操作的详细信息。

UseDefaultFiles(IApplicationBuilder)

在当前路径上启用默认文件映射

UseDefaultFiles(IApplicationBuilder, DefaultFilesOptions)

使用给定的选项启用默认文件映射

UseDefaultFiles(IApplicationBuilder, String)

为给定请求路径启用默认文件映射

UseDeveloperExceptionPage(IApplicationBuilder)

从管道捕获同步和异步 Exception 实例,并生成 HTML 错误响应。

UseDeveloperExceptionPage(IApplicationBuilder, DeveloperExceptionPageOptions)

从管道捕获同步和异步 Exception 实例,并生成 HTML 错误响应。

UseDirectoryBrowser(IApplicationBuilder)

在当前路径上启用目录浏览

UseDirectoryBrowser(IApplicationBuilder, DirectoryBrowserOptions)

使用给定的选项启用目录浏览

UseDirectoryBrowser(IApplicationBuilder, String)

启用给定请求路径的目录浏览

Map(IEndpointRouteBuilder, RoutePattern, RequestDelegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP 请求匹配的 。

Map(IEndpointRouteBuilder, RoutePattern, Delegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP 请求匹配的 。

Map(IEndpointRouteBuilder, String, RequestDelegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP 请求匹配的 。

Map(IEndpointRouteBuilder, String, Delegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP 请求匹配的 。

MapDelete(IEndpointRouteBuilder, String, RequestDelegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP DELETE 请求匹配的 。

MapDelete(IEndpointRouteBuilder, String, Delegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP DELETE 请求匹配的 。

MapFallback(IEndpointRouteBuilder, Delegate)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。

MapFallback(IEndpointRouteBuilder, String, Delegate)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,使其与提供的模式匹配,其优先级可能最低。

MapGet(IEndpointRouteBuilder, String, RequestDelegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP GET 请求匹配的 。

MapGet(IEndpointRouteBuilder, String, Delegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP GET 请求匹配的 。

MapGroup(IEndpointRouteBuilder, RoutePattern)

创建一个 RouteGroupBuilder ,用于定义以指定 prefix为前缀的所有终结点。

MapGroup(IEndpointRouteBuilder, String)

创建一个 RouteGroupBuilder ,用于定义以指定 prefix为前缀的所有终结点。

MapMethods(IEndpointRouteBuilder, String, IEnumerable<String>, RequestDelegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定 HTTP 方法和模式的 HTTP 请求匹配的 。

MapMethods(IEndpointRouteBuilder, String, IEnumerable<String>, Delegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定 HTTP 方法和模式的 HTTP 请求匹配的 。

MapPatch(IEndpointRouteBuilder, String, RequestDelegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP PATCH 请求匹配的 。

MapPatch(IEndpointRouteBuilder, String, Delegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP PATCH 请求匹配的 。

MapPost(IEndpointRouteBuilder, String, RequestDelegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP POST 请求匹配的 。

MapPost(IEndpointRouteBuilder, String, Delegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP POST 请求匹配的 。

MapPut(IEndpointRouteBuilder, String, RequestDelegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP PUT 请求匹配的 。

MapPut(IEndpointRouteBuilder, String, Delegate)

RouteEndpoint将 添加到IEndpointRouteBuilder与指定模式的 HTTP PUT 请求匹配的 。

UseEndpoints(IApplicationBuilder, Action<IEndpointRouteBuilder>)

Microsoft.AspNetCore.Routing.EndpointMiddleware使用从配置的 IEndpointRouteBuilder生成的实例,将中间件添加到指定的 IApplicationBuilderEndpointDataSource 。 将 Microsoft.AspNetCore.Routing.EndpointMiddleware 执行与 Endpoint 当前请求关联的 。

UseRouting(IApplicationBuilder)

将中间 Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware 件添加到指定的 IApplicationBuilder

UseExceptionHandler(IApplicationBuilder)

将中间件添加到管道中,该中间件将捕获异常、记录异常,并在备用管道中重新执行请求。 如果响应已启动,则不会重新执行请求。

UseExceptionHandler(IApplicationBuilder, ExceptionHandlerOptions)

将中间件添加到管道中,该中间件将捕获异常、记录异常,并在备用管道中重新执行请求。 如果响应已启动,则不会重新执行请求。

UseExceptionHandler(IApplicationBuilder, Action<IApplicationBuilder>)

将中间件添加到管道中,该中间件将捕获异常、记录异常,并在备用管道中重新执行请求。 如果响应已启动,则不会重新执行请求。

UseExceptionHandler(IApplicationBuilder, String)

将中间件添加到管道中,该中间件将捕获异常、记录异常、重置请求路径,然后重新执行请求。 如果响应已启动,则不会重新执行请求。

UseExceptionHandler(IApplicationBuilder, String, Boolean)

将中间件添加到管道中,该中间件将捕获异常、记录异常、重置请求路径,然后重新执行请求。 如果响应已启动,则不会重新执行请求。

MapFallback(IEndpointRouteBuilder, RequestDelegate)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。

MapFallback(IEndpointRouteBuilder, String, RequestDelegate)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,使其与提供的模式匹配,其优先级可能最低。

UseFileServer(IApplicationBuilder)

为当前目录中的当前请求路径启用所有静态文件中间件(目录浏览除外)。

UseFileServer(IApplicationBuilder, FileServerOptions)

使用给定的选项启用所有静态文件中间件

UseFileServer(IApplicationBuilder, Boolean)

为当前目录中的当前请求路径启用所有静态文件中间件。

UseFileServer(IApplicationBuilder, String)

为同名目录中的给定请求路径启用所有静态文件中间件(目录浏览除外)

UseForwardedHeaders(IApplicationBuilder)

将转发的标头应用于当前请求上的匹配字段。

按照约定,HTTP 代理在已知的 HTTP 标头中转发来自客户端的信息。 读取 ForwardedHeadersMiddleware 这些标头并填充 HttpContext 上的关联字段。

UseForwardedHeaders(IApplicationBuilder, ForwardedHeadersOptions)

将转发的标头应用于当前请求上的匹配字段。

按照约定,HTTP 代理在已知的 HTTP 标头中转发来自客户端的信息。 读取 ForwardedHeadersMiddleware 这些标头并填充 HttpContext 上的关联字段。

UseHeaderPropagation(IApplicationBuilder)

添加一个中间件,用于收集要传播到 的 HttpClient标头。

UseHealthChecks(IApplicationBuilder, PathString)

添加提供运行状况检查状态的中间件。

UseHealthChecks(IApplicationBuilder, PathString, HealthCheckOptions)

添加提供运行状况检查状态的中间件。

UseHealthChecks(IApplicationBuilder, PathString, Int32)

添加提供运行状况检查状态的中间件。

UseHealthChecks(IApplicationBuilder, PathString, Int32, HealthCheckOptions)

添加提供运行状况检查状态的中间件。

UseHealthChecks(IApplicationBuilder, PathString, String)

添加提供运行状况检查状态的中间件。

UseHealthChecks(IApplicationBuilder, PathString, String, HealthCheckOptions)

添加提供运行状况检查状态的中间件。

MapHealthChecks(IEndpointRouteBuilder, String)

使用指定模板将运行状况检查终结点添加到 IEndpointRouteBuilder

MapHealthChecks(IEndpointRouteBuilder, String, HealthCheckOptions)

使用指定的模板和选项将运行状况检查终结点添加到 IEndpointRouteBuilder

UseHostFiltering(IApplicationBuilder)

添加中间件,用于按允许的主机标头筛选请求。 无效请求将被拒绝,状态代码为 400。

UseHsts(IApplicationBuilder)

添加中间件以使用 HSTS,以添加 Strict-Transport-Security 标头。

UseHttpLogging(IApplicationBuilder)

添加可记录 HTTP 请求和响应的中间件。

UseW3CLogging(IApplicationBuilder)

添加一个中间件,该中间件可以记录 W3C 格式的服务器日志的 HTTP 请求和响应。

UseHttpMethodOverride(IApplicationBuilder)

允许传入的 POST 请求替代标头中指定的类型的方法类型。 当客户端限制为发送 GET 或 POST 方法,但想要调用其他 HTTP 方法时,将使用此中间件。 默认情况下,X-HTTP-Method-Override 请求标头用于指定要通过隧道传输的 HTTP 方法。

UseHttpMethodOverride(IApplicationBuilder, HttpMethodOverrideOptions)

允许传入 POST 请求替代窗体中指定的类型的方法类型。 当客户端限制为发送 GET 或 POST 方法,但想要调用其他 HTTP 方法时,将使用此中间件。

UseHttpsRedirection(IApplicationBuilder)

添加用于将 HTTP 请求重定向到 HTTPS 的中间件。

MapHub<THub>(IEndpointRouteBuilder, String)

将具有指定路径的传入请求映射到指定 Hub 类型。

MapHub<THub>(IEndpointRouteBuilder, String, Action<HttpConnectionDispatcherOptions>)

将具有指定路径的传入请求映射到指定 Hub 类型。

Map(IApplicationBuilder, PathString, Action<IApplicationBuilder>)

根据给定请求路径的匹配项对请求管道进行分支。 如果请求路径以给定路径开头,则执行分支。

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

根据给定请求路径的匹配项对请求管道进行分支。 如果请求路径以给定路径开头,则执行分支。

Map(IApplicationBuilder, String, Action<IApplicationBuilder>)

根据给定请求路径的匹配项对请求管道进行分支。 如果请求路径以给定路径开头,则执行分支。

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

根据给定谓词的结果对请求管道执行分支操作。

UseMigrationsEndPoint(IApplicationBuilder)

处理请求以执行迁移操作。 中间件将侦听对 DefaultPath发出的请求。

UseMigrationsEndPoint(IApplicationBuilder, MigrationsEndPointOptions)

处理请求以执行迁移操作。 中间件将侦听对 中 options配置的路径的请求。

UseMvc(IApplicationBuilder)

将 MVC 添加到 IApplicationBuilder 请求执行管道。

UseMvc(IApplicationBuilder, Action<IRouteBuilder>)

将 MVC 添加到 IApplicationBuilder 请求执行管道。

UseMvcWithDefaultRoute(IApplicationBuilder)

使用名为“default”的默认路由和以下模板将 MVC 添加到 IApplicationBuilder 请求执行管道:“{controller=Home}/{action=Index}/{id?}”。

UseOutputCache(IApplicationBuilder)

用于配置 HTTP 管道和路由的 Web 应用程序。

UseOwin(IApplicationBuilder)

将 OWIN 管道添加到指定的 IApplicationBuilder

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

将 OWIN 中间件管道添加到指定的 IApplicationBuilder

UseRateLimiter(IApplicationBuilder)

为应用程序启用速率限制。

UseRateLimiter(IApplicationBuilder, RateLimiterOptions)

为应用程序启用速率限制。

MapRazorComponents<TRootComponent>(IEndpointRouteBuilder)

将指定 TRootComponent 中定义的页面组件映射到给定程序集,并在路由匹配时呈现 由 TRootComponent 指定的组件。

MapDynamicPageRoute<TTransformer>(IEndpointRouteBuilder, String)

向 添加专用 RouteEndpoint 的 , IEndpointRouteBuilder 它将尝试使用 生成的 TTransformer路由值选择页面。

MapDynamicPageRoute<TTransformer>(IEndpointRouteBuilder, String, Object)

向 添加专用 RouteEndpoint 的 , IEndpointRouteBuilder 它将尝试使用 生成的 TTransformer路由值选择页面。

MapDynamicPageRoute<TTransformer>(IEndpointRouteBuilder, String, Object, Int32)

向 添加专用 RouteEndpoint 的 , IEndpointRouteBuilder 它将尝试使用 生成的 TTransformer路由值选择页面。

MapFallbackToAreaPage(IEndpointRouteBuilder, String, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。 请求将路由到与 、 和 area匹配page的页面终结点。

MapFallbackToAreaPage(IEndpointRouteBuilder, String, String, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。 请求将路由到与 、 和 area匹配page的页面终结点。

MapFallbackToPage(IEndpointRouteBuilder, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。 请求将路由到与 匹配 page的页面终结点。

MapFallbackToPage(IEndpointRouteBuilder, String, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,它将匹配具有尽可能低优先级的非文件名的请求。 请求将路由到与 匹配 page的页面终结点。

MapRazorPages(IEndpointRouteBuilder)

将 Razor Pages 的终结点添加到 IEndpointRouteBuilder

UseRequestDecompression(IApplicationBuilder)

添加用于动态解压缩 HTTP 请求正文的中间件。

UseRequestTimeouts(IApplicationBuilder)

为应用程序启用请求超时。

默认情况下不配置超时。 必须在 、RequestTimeoutAttribute终结点上的 中配置它们,或使用 WithRequestTimeout 路由扩展进行配置RequestTimeoutOptions

UseResponseCaching(IApplicationBuilder)

ResponseCachingMiddleware添加 用于缓存 HTTP 响应的 。

UseResponseCompression(IApplicationBuilder)

添加用于动态压缩 HTTP 响应的中间件。

UseRewriter(IApplicationBuilder)

检查给定 URL 是否与规则和条件匹配,并在匹配时修改 HttpContext。

UseRewriter(IApplicationBuilder, RewriteOptions)

检查给定 URL 是否与规则和条件匹配,并在匹配时修改 HttpContext。

UseRouter(IApplicationBuilder, IRouter)

使用 RouterMiddleware 指定的 IApplicationBuilder 将中间件添加到指定的 IRouter

UseRouter(IApplicationBuilder, Action<IRouteBuilder>)

RouterMiddleware使用从配置的 IRouteBuilder生成的 将中间件添加到指定的 IApplicationBuilderIRouter

Run(IApplicationBuilder, RequestDelegate)

将终端中间件委托添加到应用程序的请求管道。

UseSession(IApplicationBuilder)

添加 以 SessionMiddleware 自动启用应用程序的会话状态。

UseSession(IApplicationBuilder, SessionOptions)

添加 以 SessionMiddleware 自动启用应用程序的会话状态。

UseSpa(IApplicationBuilder, Action<ISpaBuilder>)

通过返回单页应用程序 (SPA) 的默认页,处理中间件链中此点的所有请求。

此中间件应放置在链的后期,以便优先处理静态文件、MVC 操作等的其他中间件。

UseStaticFiles(IApplicationBuilder)

为当前请求路径启用静态文件服务

UseStaticFiles(IApplicationBuilder, StaticFileOptions)

使用给定的选项启用静态文件提供

UseStaticFiles(IApplicationBuilder, String)

为给定请求路径启用静态文件服务

MapFallbackToFile(IEndpointRouteBuilder, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,以匹配具有可能最低优先级的非文件名的请求。 请求将路由到尝试 StaticFileMiddleware 为 指定的文件提供服务的 filePath

MapFallbackToFile(IEndpointRouteBuilder, String, StaticFileOptions)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,以匹配具有可能最低优先级的非文件名的请求。 请求将路由到尝试 StaticFileMiddleware 为 指定的文件提供服务的 filePath

MapFallbackToFile(IEndpointRouteBuilder, String, String)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,以匹配具有可能最低优先级的非文件名的请求。 请求将路由到尝试 StaticFileMiddleware 为 指定的文件提供服务的 filePath

MapFallbackToFile(IEndpointRouteBuilder, String, String, StaticFileOptions)

将专用 RouteEndpoint 化 添加到 IEndpointRouteBuilder ,以匹配具有可能最低优先级的非文件名的请求。 请求将路由到尝试 StaticFileMiddleware 为 指定的文件提供服务的 filePath

UseStatusCodePages(IApplicationBuilder)

使用默认响应处理程序添加 StatusCodePages 中间件,用于检查状态代码在 400 到 599 之间且没有正文的响应。

UseStatusCodePages(IApplicationBuilder, StatusCodePagesOptions)

使用给定选项添加 StatusCodePages 中间件,用于检查状态代码在 400 到 599 之间且没有正文的响应。

UseStatusCodePages(IApplicationBuilder, Action<IApplicationBuilder>)

将 StatusCodePages 中间件添加到管道,其中包含要执行的指定备用中间件管道以生成响应正文。

UseStatusCodePages(IApplicationBuilder, Func<StatusCodeContext,Task>)

添加具有指定处理程序的 StatusCodePages 中间件,用于检查状态代码介于 400 和 599 之间且没有正文的响应。

UseStatusCodePages(IApplicationBuilder, String, String)

添加具有要发送的指定响应正文的 StatusCodePages 中间件。 这可能包括状态代码的“”{0}占位符。 中间件检查状态代码在 400 到 599 之间且没有正文的响应。

UseStatusCodePagesWithRedirects(IApplicationBuilder, String)

将 StatusCodePages 中间件添加到管道。 指定应通过使用给定的位置 URL 模板进行重定向来处理响应。 这可能包括状态代码的“”{0}占位符。 以“~”开头的 URL 将预先添加 PathBase,其中任何其他 URL 将按原样使用。

UseStatusCodePagesWithReExecute(IApplicationBuilder, String, String)

将 StatusCodePages 中间件添加到管道。 指定应使用备用路径重新执行请求管道,从而生成响应正文。 此路径可能包含状态代码的“”{0}占位符。

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

将内联定义的中间件委托添加到应用程序的请求管道。 如果不调用下一个函数,请改用 Run(IApplicationBuilder, RequestDelegate)

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

将内联定义的中间件委托添加到应用程序的请求管道。 如果不调用下一个函数,请改用 Run(IApplicationBuilder, RequestDelegate)

为了获得更好的性能,首选使用 Use(IApplicationBuilder, Func<HttpContext,RequestDelegate,Task>) ,如下所示:

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

将中间件类型添加到应用程序的请求管道。

UseMiddleware<TMiddleware>(IApplicationBuilder, Object[])

将中间件类型添加到应用程序的请求管道。

UsePathBase(IApplicationBuilder, PathString)

添加一个中间件,用于从请求路径中提取指定的路径基,并将其追加到请求路径基。

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

有条件地在请求管道中创建重新加入main管道的分支。

UseWebAssemblyDebugging(IApplicationBuilder)

在 Chromium 开发工具中添加调试 Blazor WebAssembly 应用程序所需的中间件。

UseWebSockets(IApplicationBuilder)

WebSocketMiddleware将 添加到请求管道。

UseWebSockets(IApplicationBuilder, WebSocketOptions)

WebSocketMiddleware将 添加到请求管道。

UseWelcomePage(IApplicationBuilder)

将 WelcomePageMiddleware 添加到管道。

UseWelcomePage(IApplicationBuilder, WelcomePageOptions)

使用给定的选项将 WelcomePageMiddleware 添加到管道。

UseWelcomePage(IApplicationBuilder, PathString)

将 WelcomePageMiddleware 添加到具有给定的路径的管道。

UseWelcomePage(IApplicationBuilder, String)

将 WelcomePageMiddleware 添加到具有给定的路径的管道。

MapIdentityApi<TUser>(IEndpointRouteBuilder)

使用 ASP.NET Core Identity 添加用于注册、登录和注销的终结点。

MapShortCircuit(IEndpointRouteBuilder, Int32, String[])

将 (RouteEndpointIEndpointRouteBuilder 指定前缀的所有谓词) 匹配 HTTP 请求的 。

UseHttpLoggingMiddleware(IApplicationBuilder)

将传入的 HTTP 请求日志记录中间件注册到 IApplicationBuilder

UseRequestCheckpoint(IApplicationBuilder)

将请求检查点相关的中间件注册到管道中。

UseRequestLatencyTelemetry(IApplicationBuilder)

将请求延迟遥测中间件添加到 IApplicationBuilder 请求执行管道。

UseSpaStaticFiles(IApplicationBuilder)

将应用程序配置为为单页应用程序 (SPA) 提供静态文件。 将使用已注册 ISpaStaticFileProvider 的服务查找文件。

UseSpaStaticFiles(IApplicationBuilder, StaticFileOptions)

将应用程序配置为为单页应用程序 (SPA) 提供静态文件。 将使用已注册 ISpaStaticFileProvider 的服务查找文件。

适用于