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 应用程序。

扩展方法

名称 说明
Map(IApplicationBuilder, PathString, Action<IApplicationBuilder>)

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

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

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

Map(IApplicationBuilder, String, Action<IApplicationBuilder>)

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

Map(IEndpointRouteBuilder, RoutePattern, Delegate)

向与指定模式的 HTTP 请求匹配的项添加一个RouteEndpointIEndpointRouteBuilder

Map(IEndpointRouteBuilder, RoutePattern, RequestDelegate)

向与指定模式的 HTTP 请求匹配的项添加一个RouteEndpointIEndpointRouteBuilder

Map(IEndpointRouteBuilder, String, Delegate)

向与指定模式的 HTTP 请求匹配的项添加一个RouteEndpointIEndpointRouteBuilder

Map(IEndpointRouteBuilder, String, RequestDelegate)

向与指定模式的 HTTP 请求匹配的项添加一个RouteEndpointIEndpointRouteBuilder

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

向控制器操作 IEndpointRouteBuilder 添加终结点,并指定具有给定 nameareaNamepatterndefaultsconstraintsdataTokens路由。

MapBlazorHub(IEndpointRouteBuilder, Action<HttpConnectionDispatcherOptions>)

将 Blazor Hub 映射到默认路径。

MapBlazorHub(IEndpointRouteBuilder, String, Action<HttpConnectionDispatcherOptions>)

将 Blazor Hub 映射到路径 path

MapBlazorHub(IEndpointRouteBuilder, String)

将 Blazor Hub 映射到路径 path

MapBlazorHub(IEndpointRouteBuilder)

将 Blazor Hub 映射到默认路径。

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

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

MapConnectionHandler<TConnectionHandler>(IEndpointRouteBuilder, String)

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

MapConnections(IEndpointRouteBuilder, String, Action<IConnectionBuilder>)

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

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

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

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

向控制器操作 IEndpointRouteBuilder 添加终结点,并指定具有给定 namepatterndefaultsconstraintsdataTokens路由。

MapControllers(IEndpointRouteBuilder)

将控制器操作的终结点添加到 IEndpointRouteBuilder 不指定任何路由。

MapDefaultControllerRoute(IEndpointRouteBuilder)

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

MapDelete(IEndpointRouteBuilder, String, Delegate)

向与指定模式的 HTTP DELETE 请求匹配的项添加一个RouteEndpointIEndpointRouteBuilder

MapDelete(IEndpointRouteBuilder, String, RequestDelegate)

向与指定模式的 HTTP DELETE 请求匹配的项添加一个RouteEndpointIEndpointRouteBuilder

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

使用路由TTransformer值生成的路由值,将专用RouteEndpointIEndpointRouteBuilder尝试选择控制器操作。

MapDynamicControllerRoute<TTransformer>(IEndpointRouteBuilder, String, Object)

使用路由TTransformer值生成的路由值,将专用RouteEndpointIEndpointRouteBuilder尝试选择控制器操作。

MapDynamicControllerRoute<TTransformer>(IEndpointRouteBuilder, String)

使用路由TTransformer值生成的路由值,将专用RouteEndpointIEndpointRouteBuilder尝试选择控制器操作。

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

添加专用 RouteEndpointIEndpointRouteBuilder 将尝试使用由 TTransformer其生成的路由值选择页面。

MapDynamicPageRoute<TTransformer>(IEndpointRouteBuilder, String, Object)

添加专用 RouteEndpointIEndpointRouteBuilder 将尝试使用由 TTransformer其生成的路由值选择页面。

MapDynamicPageRoute<TTransformer>(IEndpointRouteBuilder, String)

添加专用 RouteEndpointIEndpointRouteBuilder 将尝试使用由 TTransformer其生成的路由值选择页面。

MapFallback(IEndpointRouteBuilder, Delegate)

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。

MapFallback(IEndpointRouteBuilder, RequestDelegate)

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。

MapFallback(IEndpointRouteBuilder, String, Delegate)

将专用 RouteEndpoint 化添加到 IEndpointRouteBuilder 将与提供的模式匹配且优先级最低的模式。

MapFallback(IEndpointRouteBuilder, String, RequestDelegate)

将专用 RouteEndpoint 化添加到 IEndpointRouteBuilder 将与提供的模式匹配且优先级最低的模式。

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

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。 请求将路由到匹配 actioncontroller控制器终结点,以及 area

MapFallbackToAreaController(IEndpointRouteBuilder, String, String, String)

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。 请求将路由到匹配 actioncontroller控制器终结点,以及 area

MapFallbackToAreaPage(IEndpointRouteBuilder, String, String, String)

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。 请求将路由到匹配 page的页面终结点,以及 area

MapFallbackToAreaPage(IEndpointRouteBuilder, String, String)

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。 请求将路由到匹配 page的页面终结点,以及 area

MapFallbackToController(IEndpointRouteBuilder, String, String, String)

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。 请求将路由到匹配 action的控制器终结点,以及 controller

MapFallbackToController(IEndpointRouteBuilder, String, String)

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。 请求将路由到匹配 action的控制器终结点,以及 controller

MapFallbackToFile(IEndpointRouteBuilder, String, StaticFileOptions)

将专用 RouteEndpointIEndpointRouteBuilder 与非文件名的请求匹配且优先级最低的专用项。 请求将路由到 StaticFileMiddleware 尝试为指定的 filePath文件提供服务的尝试。

MapFallbackToFile(IEndpointRouteBuilder, String, String, StaticFileOptions)

将专用 RouteEndpointIEndpointRouteBuilder 与非文件名的请求匹配且优先级最低的专用项。 请求将路由到 StaticFileMiddleware 尝试为指定的 filePath文件提供服务的尝试。

MapFallbackToFile(IEndpointRouteBuilder, String, String)

将专用 RouteEndpointIEndpointRouteBuilder 与非文件名的请求匹配且优先级最低的专用项。 请求将路由到 StaticFileMiddleware 尝试为指定的 filePath文件提供服务的尝试。

MapFallbackToFile(IEndpointRouteBuilder, String)

将专用 RouteEndpointIEndpointRouteBuilder 与非文件名的请求匹配且优先级最低的专用项。 请求将路由到 StaticFileMiddleware 尝试为指定的 filePath文件提供服务的尝试。

MapFallbackToPage(IEndpointRouteBuilder, String, String)

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。 请求将路由到匹配 page的页面终结点。

MapFallbackToPage(IEndpointRouteBuilder, String)

将专用 RouteEndpointIEndpointRouteBuilder 将匹配非文件名的请求,其优先级最低。 请求将路由到匹配 page的页面终结点。

MapGet(IEndpointRouteBuilder, String, Delegate)

向与指定模式的 HTTP GET 请求匹配的 A RouteEndpointIEndpointRouteBuilder

MapGet(IEndpointRouteBuilder, String, RequestDelegate)

向与指定模式的 HTTP GET 请求匹配的 A RouteEndpointIEndpointRouteBuilder

MapGroup(IEndpointRouteBuilder, RoutePattern)

创建一个 RouteGroupBuilder 用于定义具有指定 prefix前缀的终结点。

MapGroup(IEndpointRouteBuilder, String)

创建一个 RouteGroupBuilder 用于定义具有指定 prefix前缀的终结点。

MapHealthChecks(IEndpointRouteBuilder, String, HealthCheckOptions)

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

MapHealthChecks(IEndpointRouteBuilder, String)

将运行状况检查终结点添加到 IEndpointRouteBuilder 具有指定模板的终结点。

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

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

MapHub<THub>(IEndpointRouteBuilder, String)

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

MapIdentityApi<TUser>(IEndpointRouteBuilder)

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

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

向与指定 HTTP 方法和模式的 HTTP 请求匹配的 A RouteEndpointIEndpointRouteBuilder

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

向与指定 HTTP 方法和模式的 HTTP 请求匹配的 A RouteEndpointIEndpointRouteBuilder

MapOpenApi(IEndpointRouteBuilder, String)

将终结点注册到当前应用程序以解析与当前应用程序关联的 OpenAPI 文档。

MapPatch(IEndpointRouteBuilder, String, Delegate)

向与指定模式的 HTTP PATCH 请求匹配的 A RouteEndpointIEndpointRouteBuilder

MapPatch(IEndpointRouteBuilder, String, RequestDelegate)

向与指定模式的 HTTP PATCH 请求匹配的 A RouteEndpointIEndpointRouteBuilder

MapPost(IEndpointRouteBuilder, String, Delegate)

向与指定模式的 HTTP POST 请求匹配的 A RouteEndpointIEndpointRouteBuilder

MapPost(IEndpointRouteBuilder, String, RequestDelegate)

向与指定模式的 HTTP POST 请求匹配的 A RouteEndpointIEndpointRouteBuilder

MapPut(IEndpointRouteBuilder, String, Delegate)

向与指定模式的 HTTP PUT 请求匹配的 A RouteEndpointIEndpointRouteBuilder

MapPut(IEndpointRouteBuilder, String, RequestDelegate)

向与指定模式的 HTTP PUT 请求匹配的 A RouteEndpointIEndpointRouteBuilder

MapRazorComponents<TRootComponent>(IEndpointRouteBuilder)

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

MapRazorPages(IEndpointRouteBuilder)

将 Razor Pages 的终结点添加到 .IEndpointRouteBuilder

MapShortCircuit(IEndpointRouteBuilder, Int32, String[])

向与指定前缀的 HTTP 请求(所有谓词)匹配的项添加一个RouteEndpointIEndpointRouteBuilder

MapStaticAssets(IEndpointRouteBuilder, String)

将生成过程中生成的静态文件映射为终结点。

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

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

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);
});

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

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

UseAntiforgery(IApplicationBuilder)

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

UseAuthentication(IApplicationBuilder)

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

UseAuthorization(IApplicationBuilder)

将指定 AuthorizationMiddleware 添加到启用授权功能的指定 IApplicationBuilder

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

UseBlazorFrameworkFiles(IApplicationBuilder, PathString)

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

UseBlazorFrameworkFiles(IApplicationBuilder)

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

UseCertificateForwarding(IApplicationBuilder)

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

UseConcurrencyLimiter(IApplicationBuilder)
已过时.

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

UseCookiePolicy(IApplicationBuilder, CookiePolicyOptions)

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

UseCookiePolicy(IApplicationBuilder)

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

UseCors(IApplicationBuilder, Action<CorsPolicyBuilder>)

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

UseCors(IApplicationBuilder, String)

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

UseCors(IApplicationBuilder)

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

UseDatabaseErrorPage(IApplicationBuilder, DatabaseErrorPageOptions)
已过时.

从管道中捕获可以使用 Entity Framework 迁移解析的同步数据库和异步数据库相关异常。 发生这些异常时,将生成 HTML 响应,其中包含可能解决问题的操作的详细信息。

UseDatabaseErrorPage(IApplicationBuilder)
已过时.

从管道中捕获可以使用 Entity Framework 迁移解析的同步数据库和异步数据库相关异常。 发生这些异常时,将生成 HTML 响应,其中包含可能解决问题的操作的详细信息。

UseDefaultFiles(IApplicationBuilder, DefaultFilesOptions)

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

UseDefaultFiles(IApplicationBuilder, String)

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

UseDefaultFiles(IApplicationBuilder)

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

UseDeveloperExceptionPage(IApplicationBuilder, DeveloperExceptionPageOptions)

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

UseDeveloperExceptionPage(IApplicationBuilder)

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

UseDirectoryBrowser(IApplicationBuilder, DirectoryBrowserOptions)

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

UseDirectoryBrowser(IApplicationBuilder, String)

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

UseDirectoryBrowser(IApplicationBuilder)

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

UseEndpoints(IApplicationBuilder, Action<IEndpointRouteBuilder>)

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

UseExceptionHandler(IApplicationBuilder, Action<IApplicationBuilder>)

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

UseExceptionHandler(IApplicationBuilder, ExceptionHandlerOptions)

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

UseExceptionHandler(IApplicationBuilder, String, Boolean)

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

UseExceptionHandler(IApplicationBuilder, String)

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

UseExceptionHandler(IApplicationBuilder)

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

UseFileServer(IApplicationBuilder, Boolean)

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

UseFileServer(IApplicationBuilder, FileServerOptions)

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

UseFileServer(IApplicationBuilder, String)

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

UseFileServer(IApplicationBuilder)

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

UseForwardedHeaders(IApplicationBuilder, ForwardedHeadersOptions)

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

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

UseForwardedHeaders(IApplicationBuilder)

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

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

UseHeaderPropagation(IApplicationBuilder)

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

UseHealthChecks(IApplicationBuilder, PathString, HealthCheckOptions)

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

UseHealthChecks(IApplicationBuilder, PathString, Int32, HealthCheckOptions)

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

UseHealthChecks(IApplicationBuilder, PathString, Int32)

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

UseHealthChecks(IApplicationBuilder, PathString, String, HealthCheckOptions)

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

UseHealthChecks(IApplicationBuilder, PathString, String)

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

UseHealthChecks(IApplicationBuilder, PathString)

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

UseHostFiltering(IApplicationBuilder)

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

UseHsts(IApplicationBuilder)

添加用于使用 HSTS 的中间件,这将添加 Strict-Transport-Security 标头。

UseHttpLogging(IApplicationBuilder)

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

UseHttpLoggingMiddleware(IApplicationBuilder)

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

UseHttpMethodOverride(IApplicationBuilder, HttpMethodOverrideOptions)

允许传入 POST 请求重写采用表单中指定的类型的方法类型。 当客户端仅限于发送 GET 或 POST 方法,但想要调用其他 HTTP 方法时,将使用此中间件。

UseHttpMethodOverride(IApplicationBuilder)

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

UseHttpsRedirection(IApplicationBuilder)

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

UseMiddleware(IApplicationBuilder, Type, Object[])

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

UseMiddleware<TMiddleware>(IApplicationBuilder, Object[])

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

UseMigrationsEndPoint(IApplicationBuilder, MigrationsEndPointOptions)

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

UseMigrationsEndPoint(IApplicationBuilder)

处理执行迁移操作的请求。 中间件将侦听向 . DefaultPath.

UseMvc(IApplicationBuilder, Action<IRouteBuilder>)

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

UseMvc(IApplicationBuilder)

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

UseMvcWithDefaultRoute(IApplicationBuilder)

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

UseOutputCache(IApplicationBuilder)

添加用于缓存 HTTP 响应的 Microsoft.AspNetCore.OutputCaching.OutputCacheMiddleware

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

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

UseOwin(IApplicationBuilder)

将 OWIN 管道添加到指定的 IApplicationBuilder

UsePathBase(IApplicationBuilder, PathString)

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

UseRateLimiter(IApplicationBuilder, RateLimiterOptions)

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

UseRateLimiter(IApplicationBuilder)

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

UseRequestCheckpoint(IApplicationBuilder)

注册用于请求检查点的中间件。

UseRequestCheckpoint(IApplicationBuilder)

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

UseRequestDecompression(IApplicationBuilder)

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

UseRequestLatencyTelemetry(IApplicationBuilder)

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

UseRequestLatencyTelemetry(IApplicationBuilder)

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

UseRequestLocalization(IApplicationBuilder, Action<RequestLocalizationOptions>)

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

UseRequestLocalization(IApplicationBuilder, RequestLocalizationOptions)

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

UseRequestLocalization(IApplicationBuilder, String[])

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

UseRequestLocalization(IApplicationBuilder)

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

UseRequestTimeouts(IApplicationBuilder)

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

默认情况下不会配置超时。 必须在终结点、终结点或使用 WithRequestTimeout 路由扩展中配置RequestTimeoutOptionsRequestTimeoutAttribute它们。

UseResponseCaching(IApplicationBuilder)

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

UseResponseCompression(IApplicationBuilder)

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

UseRewriter(IApplicationBuilder, RewriteOptions)

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

UseRewriter(IApplicationBuilder)

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

UseRouter(IApplicationBuilder, Action<IRouteBuilder>)

RouterMiddleware将中间件添加到具有已配置的IRouteBuilder生成的指定IApplicationBuilderIRouter项。

UseRouter(IApplicationBuilder, IRouter)

RouterMiddleware将中间件添加到具有指定项的指定 IRouterIApplicationBuilder

UseRouting(IApplicationBuilder)

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

UseSession(IApplicationBuilder, SessionOptions)

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

UseSession(IApplicationBuilder)

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

UseSpa(IApplicationBuilder, Action<ISpaBuilder>)

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

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

UseSpaStaticFiles(IApplicationBuilder, StaticFileOptions)

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

UseSpaStaticFiles(IApplicationBuilder)

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

UseStaticFiles(IApplicationBuilder, StaticFileOptions)

使用给定选项启用静态文件服务

UseStaticFiles(IApplicationBuilder, String)

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

UseStaticFiles(IApplicationBuilder)

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

UseStatusCodePages(IApplicationBuilder, Action<IApplicationBuilder>)

使用指定的备用中间件管道将 StatusCodePages 中间件添加到管道,以生成响应正文。

UseStatusCodePages(IApplicationBuilder, Func<StatusCodeContext,Task>)

添加具有指定处理程序的 StatusCodePages 中间件,该处理程序检查状态代码在 400 到 599 之间没有正文的响应。

UseStatusCodePages(IApplicationBuilder, StatusCodePagesOptions)

添加一个 StatusCodePages 中间件,其中包含用于检查状态代码在 400 到 599 之间没有正文的响应的给定选项。 如果使用HandleAsync其默认值,它将尝试使用ProblemDetailsIProblemDetailsService并回退到包含状态代码的纯文本响应。

UseStatusCodePages(IApplicationBuilder, String, String)

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

UseStatusCodePages(IApplicationBuilder)

使用默认响应处理程序添加 a StatusCodePagesMiddleware 。 中间件检查状态代码在 400 到 599 之间的响应,这些响应没有正文,当可用时 IProblemDetailsService ,会尝试生成 ProblemDetails 响应。 如果服务不可用或无法写入响应,则会生成包含状态代码的纯文本响应。

UseStatusCodePagesWithRedirects(IApplicationBuilder, String)

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

UseStatusCodePagesWithReExecute(IApplicationBuilder, String, String, Boolean)

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

UseStatusCodePagesWithReExecute(IApplicationBuilder, String, String)

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

UseW3CLogging(IApplicationBuilder)

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

UseWebAssemblyDebugging(IApplicationBuilder)

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

UseWebSockets(IApplicationBuilder, WebSocketOptions)

将请求 WebSocketMiddleware 管道添加到请求管道。

UseWebSockets(IApplicationBuilder)

将请求 WebSocketMiddleware 管道添加到请求管道。

UseWelcomePage(IApplicationBuilder, PathString)

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

UseWelcomePage(IApplicationBuilder, String)

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

UseWelcomePage(IApplicationBuilder, WelcomePageOptions)

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

UseWelcomePage(IApplicationBuilder)

将 WelcomePageMiddleware 添加到管道。

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

有条件地在请求管道中创建一个分支,该分支重新加入主管道。

适用于