.NET 6 Preview 6 现已推出,其中包括对 ASP.NET Core 的许多重大改进。

.NET 6 Preview 6 现已推出,其中包括对 ASP.NET Core 的许多重大改进。

以下是此预览版中的新功能:

  • 改进的 Blazor 可访问性
  • 必需的 Blazor 组件参数
  • 用于 JavaScript 互操作的高效字节数组传输
  • 视图组件标签助手的可选参数
  • Angular 模板更新为 Angular 12
  • 对最少 API 的 OpenAPI 支持
  • 将服务注入到没有属性的最小 API 中[FromServices]
  • 为 Kestrel 配置接受套接字
  • IHttpActivityFeature
  • SignalR 连接的长时间运行活动标记
  • WebSocket 压缩
  • SignalR WebSockets 测试服务器支持
  • OnCheckSlidingExpiration控制 cookie 更新的新事件
  • ClientCertificateMode.DelayCertificate

开始

要在 .NET 6 Preview 6 中开始使用 ASP.NET Core,请安装 .NET 6 SDK

如果你在 Windows 上使用 Visual Studio,我们建议安装 Visual Studio 2022 的最新预览版。如果您使用的是 macOS,我们建议您安装 Visual Studio 2019 for Mac 8.10 的最新预览版

要使用 .NET MAUI 和 Blazor 设置跨平台本机应用程序,请参阅.NET MAUI 入门指南 中的最新说明。请务必查看宣布 .NET MAUI 预览版 6 的博客文章,了解有关此版本中 .NET MAUI 新增功能的所有详细信息。

要安装用于提前 (AOT) 编译和运行时重新链接的最新 .NET WebAssembly 工具,请从提升的命令提示符运行以下命令:

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">dotnet workload install microsoft</span></span><span style="color:#000000"><span style="color:#000000">-</span></span><span style="color:#000000"><span style="color:#000000">net</span></span><span style="color:#000000"><span style="color:#000000">-</span></span><span style="color:#000000"><span style="color:#000000">sdk</span></span><span style="color:#000000"><span style="color:#000000">-</span></span><span style="color:#000000"><span style="color:#000000">blazorwebassembly</span></span><span style="color:#000000"><span style="color:#000000">-</span></span><span style="color:#000000"><span style="color:#000000">aot</span></span></code></span></span>

如果您之前安装了 .NET WebAssembly 工具工作负载,您可以通过从提升的命令提示符运行以下命令将其更新到 .NET 6 Preview 5:

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">dotnet workload update</span></span></code></span></span>

升级现有项目

要将现有的 ASP.NET Core 应用程序从 .NET 6 Preview 5 升级到 .NET 6 Preview 6:

  • 将所有 Microsoft.AspNetCore.* 包引用更新为.6.0.0-preview.6.*
  • 将所有 Microsoft.Extensions.* 包引用更新为.6.0.0-preview.6.*

要将 .NET MAUI Blazor 应用从 .NET 6 Preview 5 升级到 .NET 6 Preview 6,我们建议从使用 .NET 6 Preview 5 SDK 创建的新 .NET MAUI Blazor 项目开始,然后从原始项目复制代码。

查看.NET 6 的 ASP.NET Core重大更改的完整列表。

改进的 Blazor 可访问性

我们对默认 Blazor 模板进行了许多更改,以提高使用屏幕阅读器时的可访问性:

  • 我们为导航到页面时应宣布的消息添加了属性,并从调查提示组件中删除以淡化其内容。role="alert"role="alert"
  • 我们更新了Counter要添加的组件,以便在计数器更新时读取当前计数。role="status"
  • 我们转而在适当的地方使用更多语义标记元素,例如mainarticle
  • 我们ulNavBar组件中的替换为 anav以便其语义更容易识别,因此可以使用常见的屏幕阅读器键盘快捷键直接跳转到它。
  • 我们titleNavBar切换按钮上添加了一个,以便清楚地宣布它的用途。

我们还FocusOnNavigate向 Blazor添加了一个新组件,该组件在从一个页面导航到另一个页面后将 UI 焦点设置为基于 CSS 选择器的元素。您可以在默认 Blazor 模板FocusOnNavigate中的App组件中看到正在工作的组件:

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000088"><span style="color:#000088"><Router</span></span> <span style="color:#660066"><span style="color:#660066">AppAssembly</span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#008800"><span style="color:#008800">"@typeof(Program).Assembly"</span></span><span style="color:#000088"><span style="color:#000088">></span></span>
    <span style="color:#000088"><span style="color:#000088"><Found</span></span> <span style="color:#660066"><span style="color:#660066">Context</span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#008800"><span style="color:#008800">"routeData"</span></span><span style="color:#000088"><span style="color:#000088">></span></span>
        <span style="color:#000088"><span style="color:#000088"><RouteView</span></span> <span style="color:#660066"><span style="color:#660066">RouteData</span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#008800"><span style="color:#008800">"@routeData"</span></span> <span style="color:#660066"><span style="color:#660066">DefaultLayout</span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#008800"><span style="color:#008800">"@typeof(MainLayout)"</span></span> <span style="color:#000088"><span style="color:#000088">/></span></span>
        <span style="color:#000088"><span style="color:#000088"><FocusOnNavigate</span></span> <span style="color:#660066"><span style="color:#660066">RouteData</span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#008800"><span style="color:#008800">"@routeData"</span></span> <span style="color:#660066"><span style="color:#660066">Selector</span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#008800"><span style="color:#008800">"h1"</span></span> <span style="color:#000088"><span style="color:#000088">/></span></span>
    <span style="color:#000088"><span style="color:#000088"></Found></span></span>
    <span style="color:#000088"><span style="color:#000088"><NotFound></span></span>
        <span style="color:#000088"><span style="color:#000088"><LayoutView</span></span> <span style="color:#660066"><span style="color:#660066">Layout</span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#008800"><span style="color:#008800">"@typeof(MainLayout)"</span></span><span style="color:#000088"><span style="color:#000088">></span></span>
            <span style="color:#000088"><span style="color:#000088"><p</span></span> <span style="color:#660066"><span style="color:#660066">role</span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#008800"><span style="color:#008800">"alert"</span></span><span style="color:#000088"><span style="color:#000088">></span></span><span style="color:#000000"><span style="color:#000000">Sorry, there's nothing at this address.</span></span><span style="color:#000088"><span style="color:#000088"></p></span></span>
        <span style="color:#000088"><span style="color:#000088"></LayoutView></span></span>
    <span style="color:#000088"><span style="color:#000088"></NotFound></span></span>
<span style="color:#000088"><span style="color:#000088"></Router></span></span></code></span></span>

Router导航到一个新页面时,该FocusOnNavigate组件将焦点设置在该页面的顶级标题上,由屏幕阅读器读取。这是单页应用程序中的一种常见策略,用于确保在使用屏幕阅读器时适当地宣布页面导航。

我们一直在寻找方法来提高使用 ASP.NET Core 和 Blazor 构建的应用程序的可访问性。如果您对如何进一步提高可访问性有想法,可以在GitHub 上与我们分享您的建议。您还可以通过查看最近的ASP.NET Community Standup on Accessibility for Web Developers或观看最近的Let's Learn .NET:Accessibility活动,了解有关使用 .NET 构建可访问应用程序的更多信息。

必需的 Blazor 组件参数

要要求在使用组件时指定 Blazor 组件参数,请使用新属性:[EditorRequired]

SurveyPrompt.razor

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">[</span></span><span style="color:#660066"><span style="color:#660066">EditorRequired</span></span><span style="color:#000000"><span style="color:#000000">]</span></span>
<span style="color:#000000"><span style="color:#000000">[</span></span><span style="color:#660066"><span style="color:#660066">Parameter</span></span><span style="color:#000000"><span style="color:#000000">]</span></span>
<span style="color:#1e1eff"><span style="color:#1e1eff">public</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">string</span></span> <span style="color:#660066"><span style="color:#660066">Title</span></span> <span style="color:#000000"><span style="color:#000000">{</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">get</span></span><span style="color:#000000"><span style="color:#000000">;</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">set</span></span><span style="color:#000000"><span style="color:#000000">;</span></span> <span style="color:#000000"><span style="color:#000000">}</span></span></code></span></span>

如果用户在未指定所需参数的情况下尝试使用该组件,则会收到警告:

必需参数

该属性在设计时并作为构建的一部分强制执行。它不是在运行时强制执行的,也不能保证参数值不能为空。[EditorRequired]

JavaScript 互操作中的高效字节数组传输

Blazor 现在在执行 JavaScript 互操作时对字节数组提供更有效的支持。以前,发送到 JavaScript 和从 JavaScript 发送的字节数组是 Base64 编码的,因此它们可以序列化为 JSON,这增加了传输大小和 CPU 负载。这种编码现在已经在 .NET 6 中优化掉了。新的字节数组优化在Uint8Array从 JavaScript传递到 .NET时对用户是透明的。

将.NET 中的a 传递给 JavaScript 时,字节现在作为 a而不是 Base64 编码字符串接收。需要删除先前解码 Base64 编码字符串的代码。有关此重大更改的详细信息,请参阅相关公告byte[]Uint8Array

视图组件标签助手的可选参数

视图组件标签助手现在支持可选参数。如果您的视图组件有一个可选参数,您不再需要为该参数指定一个值作为标签助手属性。

因此,如果您有一个带有可选参数的视图组件,如下所示:

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#1e1eff"><span style="color:#1e1eff">class</span></span> <span style="color:#660066"><span style="color:#660066">MyViewComponent</span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span>
    <span style="color:#660066"><span style="color:#660066">IViewComponentResult</span></span> <span style="color:#660066"><span style="color:#660066">Invoke</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#1e1eff"><span style="color:#1e1eff">bool</span></span><span style="color:#000000"><span style="color:#000000"> showSomething </span></span><span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">false</span></span><span style="color:#000000"><span style="color:#000000">)</span></span> <span style="color:#000000"><span style="color:#000000">{</span></span> <span style="color:#000000"><span style="color:#000000">...</span></span> <span style="color:#000000"><span style="color:#000000">}</span></span>
<span style="color:#000000"><span style="color:#000000">}</span></span></code></span></span>

那么您现在可以将它作为标签助手调用,而无需为showSomething参数指定值:

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000088"><span style="color:#000088"><vc:my</span></span> <span style="color:#000088"><span style="color:#000088">/></span></span></code></span></span>

Angular 模板更新为 Angular 12

Angular 的 ASP.NET Core 模板现在使用 Angular 12。

最小 API 中的 OpenAPI 支持

.NET 6 预览版 4 中,我们宣布了用于在 Web 应用程序中托管和路由的最小 API。我们分享了如何仅用几行代码在单个文件中开发 API。我们新的简化 API 以更少的仪式提供了 ASP.NET 的好处。

今天,我们很高兴最小的 API 现在支持OpenAPI。借助 OpenAPI (Swagger) 支持,您现在可以轻松设置Swagger UI以可视化最少的 API 并与之交互。

使用最少的 API 配置 Swagger UI

要使用最少的 API 尝试 OpenAPI,请使用 .NET CLI 创建一个新的 ASP.NET Core 空 Web 应用程序或在 Visual Studio 中选择“ASP.NET Core Empty”。dotnet new web -o MyApi

将 Swagger UI 添加到您的应用程序

将包添加到您的应用程序Swashbuckle.AspNetCore

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">dotnet </span></span><span style="color:#1e1eff"><span style="color:#1e1eff">add</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">package</span></span> <span style="color:#660066"><span style="color:#660066">Swashbuckle</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">AspNetCore</span></span></code></span></span>

打开并更新以下配置以在您的应用程序中设置 Swagger;您需要更新以下内容:Program.cs

依赖注入:将 Swagger 文档生成器添加AddSwaggerGen到.builder.services

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">builder</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Services</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">AddEndpointsApiExplorer</span></span><span style="color:#000000"><span style="color:#000000">();</span></span><span style="color:#000000"><span style="color:#000000">

builder</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Services</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">AddSwaggerGen</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">c </span></span><span style="color:#000000"><span style="color:#000000">=></span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span><span style="color:#000000"><span style="color:#000000">
    c</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">SwaggerDoc</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#980606"><span style="color:#980606">"v1"</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">new</span></span> <span style="color:#660066"><span style="color:#660066">OpenApiInfo</span></span> <span style="color:#000000"><span style="color:#000000">{</span></span> <span style="color:#660066"><span style="color:#660066">Title</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#980606"><span style="color:#980606">"My API"</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#660066"><span style="color:#660066">Description</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#980606"><span style="color:#980606">"Docs for my API"</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#660066"><span style="color:#660066">Version</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#980606"><span style="color:#980606">"v1"</span></span> <span style="color:#000000"><span style="color:#000000">});</span></span>
<span style="color:#000000"><span style="color:#000000">});</span></span></code></span></span>

中间件:调用并将Swagger 文档和 UI 中间件添加到您的应用程序。app.UseSwaggerapp.UseSwaggerUI

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">app</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">UseSwagger</span></span><span style="color:#000000"><span style="color:#000000">();</span></span><span style="color:#000000"><span style="color:#000000">

app</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">UseSwaggerUI</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">c </span></span><span style="color:#000000"><span style="color:#000000">=></span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span><span style="color:#000000"><span style="color:#000000">
    c</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">SwaggerEndpoint</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#980606"><span style="color:#980606">"/swagger/v1/swagger.json"</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#980606"><span style="color:#980606">"My API V1"</span></span><span style="color:#000000"><span style="color:#000000">);</span></span>
<span style="color:#000000"><span style="color:#000000">});</span></span></code></span></span>

运行您的应用程序并导航到此 URL https://localhost:5001/swagger。

现在 Swagger UI 已设置,您可以可视化您的 API 并与之交互。

下面的屏幕截图是一个功能更齐全的 API,它与 SQLite 数据库一起运行。我们将在 .NET 6 Preview 7 中看到更多这些特性。

将服务注入到没有属性的最小 API 中[FromServices]

此预览版还允许开发人员在不需要属性的情况下将服务注入到他们的路由处理程序中。[FromServices]

之前:带有属性的代码[FromServices]

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">app</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">MapGet</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#980606"><span style="color:#980606">"/todos"</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">async</span></span> <span style="color:#000000"><span style="color:#000000">([</span></span><span style="color:#660066"><span style="color:#660066">FromServices</span></span><span style="color:#000000"><span style="color:#000000">]</span></span> <span style="color:#660066"><span style="color:#660066">TodoDbContext</span></span><span style="color:#000000"><span style="color:#000000">  db</span></span><span style="color:#000000"><span style="color:#000000">)</span></span> <span style="color:#000000"><span style="color:#000000">=></span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span>
    <span style="color:#1e1eff"><span style="color:#1e1eff">return</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">await</span></span><span style="color:#000000"><span style="color:#000000"> db</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Todos</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">ToListAsync</span></span><span style="color:#000000"><span style="color:#000000">();</span></span>
<span style="color:#000000"><span style="color:#000000">});</span></span></code></span></span>

之后:没有属性的代码[FromServices]

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">app</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">MapGet</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#980606"><span style="color:#980606">"/todos"</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">async</span></span> <span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#660066"><span style="color:#660066">TodoDbContext</span></span><span style="color:#000000"><span style="color:#000000"> db</span></span><span style="color:#000000"><span style="color:#000000">)</span></span> <span style="color:#000000"><span style="color:#000000">=></span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span>
    <span style="color:#1e1eff"><span style="color:#1e1eff">return</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">await</span></span><span style="color:#000000"><span style="color:#000000"> db</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Todos</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">ToListAsync</span></span><span style="color:#000000"><span style="color:#000000">();</span></span>
<span style="color:#000000"><span style="color:#000000">});</span></span></code></span></span>

我们为依赖注入容器添加了一项新功能,称为IServiceProviderIsService. 此功能允许开发人员查询容器以确定类型是否可解析。在新的路由的API使用此功能,以确定是否一个参数可以从服务的约束。

下面展示了如何使用该代码IServiceProviderIsService的能力来检测,如果MyServiceNotAService被依赖注入容器考虑服务:

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> serviceProvider </span></span><span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">new</span></span> <span style="color:#660066"><span style="color:#660066">ServiceCollection</span></span><span style="color:#000000"><span style="color:#000000">()</span></span>
    <span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">AddSingleton</span></span><span style="color:#000000"><span style="color:#000000"><</span></span><span style="color:#660066"><span style="color:#660066">MyService</span></span><span style="color:#000000"><span style="color:#000000">>()</span></span>
    <span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">BuildServiceProvider</span></span><span style="color:#000000"><span style="color:#000000">();</span></span>

<span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> detector </span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#000000"><span style="color:#000000"> serviceProvider</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">GetService</span></span><span style="color:#000000"><span style="color:#000000"><</span></span><span style="color:#660066"><span style="color:#660066">IServiceProviderIsService</span></span><span style="color:#000000"><span style="color:#000000">>();</span></span>
<span style="color:#1e1eff"><span style="color:#1e1eff">if</span></span> <span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">detector </span></span><span style="color:#1e1eff"><span style="color:#1e1eff">is</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">not</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">null</span></span><span style="color:#000000"><span style="color:#000000">)</span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span>
    <span style="color:#660066"><span style="color:#660066">Console</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">WriteLine</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">$</span></span><span style="color:#980606"><span style="color:#980606">"MyService is a service = {detector.IsService(typeof(MyService))}"</span></span><span style="color:#000000"><span style="color:#000000">);</span></span>
    <span style="color:#660066"><span style="color:#660066">Console</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">WriteLine</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">$</span></span><span style="color:#980606"><span style="color:#980606">"NotAService is a service = {detector.IsService(typeof(NotAService))}"</span></span><span style="color:#000000"><span style="color:#000000">);</span></span>
<span style="color:#000000"><span style="color:#000000">}</span></span>

<span style="color:#1e1eff"><span style="color:#1e1eff">class</span></span> <span style="color:#660066"><span style="color:#660066">MyService</span></span> <span style="color:#000000"><span style="color:#000000">{</span></span> <span style="color:#000000"><span style="color:#000000">}</span></span>
<span style="color:#1e1eff"><span style="color:#1e1eff">class</span></span> <span style="color:#660066"><span style="color:#660066">NotAService</span></span> <span style="color:#000000"><span style="color:#000000">{</span></span> <span style="color:#000000"><span style="color:#000000">}</span></span></code></span></span>

为 Kestrel 配置接受套接字

我们添加了一个回调SocketTransportOptions,允许您通过创建自己的套接字并绑定到指定的端点来控制接受套接字的创建。如果您只想在绑定后改变套接字,您可以在 上调用CreateDefaultBoundListenSocket静态辅助方法SocketTransportOptions

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> builder </span></span><span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#660066"><span style="color:#660066">WebApplication</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">CreateBuilder</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">args</span></span><span style="color:#000000"><span style="color:#000000">);</span></span><span style="color:#000000"><span style="color:#000000">
builder</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">WebHost</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">UseSockets</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">options </span></span><span style="color:#000000"><span style="color:#000000">=></span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span><span style="color:#000000"><span style="color:#000000">
    options</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">CreateBoundListenSocket</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">endpoint</span></span><span style="color:#000000"><span style="color:#000000">)</span></span> <span style="color:#000000"><span style="color:#000000">=></span></span>
    <span style="color:#000000"><span style="color:#000000">{</span></span>
        <span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> socket </span></span><span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#660066"><span style="color:#660066">SocketTransportOptions</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">CreateDefaultBoundListenSocket</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">endpoint</span></span><span style="color:#000000"><span style="color:#000000">);</span></span>
        <span style="color:#008800"><span style="color:#008800">// Modify listen socket</span></span>
        <span style="color:#1e1eff"><span style="color:#1e1eff">return</span></span><span style="color:#000000"><span style="color:#000000"> socket</span></span><span style="color:#000000"><span style="color:#000000">;</span></span>
    <span style="color:#000000"><span style="color:#000000">};</span></span>
<span style="color:#000000"><span style="color:#000000">});</span></span></code></span></span>

IHttpActivityFeature

Activity当存在诊断侦听器时,托管会创建每个请求。现在有一项功能允许中间件访问此活动,因此可以在请求处理期间包含其他信息。

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">app</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Run</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">context </span></span><span style="color:#000000"><span style="color:#000000">=></span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span>
    <span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> activity </span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#000000"><span style="color:#000000"> context</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Features</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Get</span></span><span style="color:#000000"><span style="color:#000000"><</span></span><span style="color:#660066"><span style="color:#660066">IHttpActivityFeature</span></span><span style="color:#000000"><span style="color:#000000">>()?.</span></span><span style="color:#660066"><span style="color:#660066">Activity</span></span><span style="color:#000000"><span style="color:#000000">;</span></span>
    <span style="color:#1e1eff"><span style="color:#1e1eff">if</span></span> <span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">activity </span></span><span style="color:#1e1eff"><span style="color:#1e1eff">is</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">not</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">null</span></span><span style="color:#000000"><span style="color:#000000">)</span></span>
    <span style="color:#000000"><span style="color:#000000">{</span></span><span style="color:#000000"><span style="color:#000000">
        activity</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">AddTag</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#980606"><span style="color:#980606">"some_info"</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#980606"><span style="color:#980606">"true"</span></span><span style="color:#000000"><span style="color:#000000">);</span></span>
    <span style="color:#000000"><span style="color:#000000">}</span></span>
<span style="color:#000000"><span style="color:#000000">});</span></span></code></span></span>

SignalR 连接的长时间运行活动标记

SignalR 使用 newIHttpActivityFeature向请求活动添加“http.long_running”标签。这将被 Azure Monitor Application Insights 等 APM 服务用来过滤 SignalR 请求,以免创建长时间运行的请求警报。

WebSocket 压缩

您现在可以选择接受使用压缩的 WebSocket 连接。默认情况下压缩是关闭的,因为在加密连接上启用压缩会使应用程序受到 CRIME/BREACH 攻击。仅当您知道未发送敏感信息或关闭包含敏感信息且带有重载标志的消息的压缩时,才应启用它。注意:客户端在发送敏感信息时还需要禁用压缩,这在浏览器中使用 WebSockets 时不是一个选项。System.Net.WebSockets.WebSocketMessageFlags.DisableCompressionSendAsync

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#000000"><span style="color:#000000">app</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Run</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">context </span></span><span style="color:#000000"><span style="color:#000000">=></span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span>
    <span style="color:#1e1eff"><span style="color:#1e1eff">if</span></span> <span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">context</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">WebSockets</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">IsWebSocketRequest</span></span><span style="color:#000000"><span style="color:#000000">)</span></span>
    <span style="color:#000000"><span style="color:#000000">{</span></span>
        <span style="color:#1e1eff"><span style="color:#1e1eff">using</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> websocket </span></span><span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">await</span></span><span style="color:#000000"><span style="color:#000000"> context</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">WebSockets</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">AcceptWebSocketAsync</span></span><span style="color:#000000"><span style="color:#000000">(</span></span>
            <span style="color:#1e1eff"><span style="color:#1e1eff">new</span></span> <span style="color:#660066"><span style="color:#660066">WebSocketAcceptContext</span></span><span style="color:#000000"><span style="color:#000000">()</span></span> <span style="color:#000000"><span style="color:#000000">{</span></span> <span style="color:#660066"><span style="color:#660066">DangerousEnableCompression</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">true</span></span> <span style="color:#000000"><span style="color:#000000">});</span></span>
        <span style="color:#1e1eff"><span style="color:#1e1eff">await</span></span><span style="color:#000000"><span style="color:#000000"> websocket</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">SendAsync</span></span><span style="color:#000000"><span style="color:#000000">(...);</span></span>
        <span style="color:#1e1eff"><span style="color:#1e1eff">await</span></span><span style="color:#000000"><span style="color:#000000"> websocket</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">ReceiveAsync</span></span><span style="color:#000000"><span style="color:#000000">(...);</span></span>
        <span style="color:#1e1eff"><span style="color:#1e1eff">await</span></span><span style="color:#000000"><span style="color:#000000"> websocket</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">CloseAsync</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#660066"><span style="color:#660066">WebSocketCloseStatus</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">NormalClosure</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">null</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">default</span></span><span style="color:#000000"><span style="color:#000000">);</span></span>
    <span style="color:#000000"><span style="color:#000000">}</span></span>
<span style="color:#000000"><span style="color:#000000">});</span></span></code></span></span>

SignalR WebSockets 测试服务器支持

我们WebSocketFactory在创建 .NET SignalR 连接时添加了选项。此选项可用于TestServer允许使用 WebSocket 传输进行测试。

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#660066"><span style="color:#660066">WebApplicationFactory</span></span><span style="color:#000000"><span style="color:#000000"><</span></span><span style="color:#660066"><span style="color:#660066">Startup</span></span><span style="color:#000000"><span style="color:#000000">></span></span><span style="color:#000000"><span style="color:#000000"> factory</span></span><span style="color:#000000"><span style="color:#000000">;</span></span>
<span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> connection </span></span><span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">new</span></span> <span style="color:#660066"><span style="color:#660066">HubConnectionBuilder</span></span><span style="color:#000000"><span style="color:#000000">()</span></span>
    <span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">WithUrl</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#980606"><span style="color:#980606">"http://localhost:53353/echo"</span></span><span style="color:#000000"><span style="color:#000000">,</span></span><span style="color:#000000"><span style="color:#000000"> options </span></span><span style="color:#000000"><span style="color:#000000">=></span></span>
    <span style="color:#000000"><span style="color:#000000">{</span></span><span style="color:#000000"><span style="color:#000000">
        options</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Transports</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#660066"><span style="color:#660066">HttpTransportType</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">WebSockets</span></span><span style="color:#000000"><span style="color:#000000">;</span></span><span style="color:#000000"><span style="color:#000000">
        options</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">HttpMessageHandlerFactory</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#000000"><span style="color:#000000"> _ </span></span><span style="color:#000000"><span style="color:#000000">=></span></span>
        <span style="color:#000000"><span style="color:#000000">{</span></span>
            <span style="color:#1e1eff"><span style="color:#1e1eff">return</span></span><span style="color:#000000"><span style="color:#000000"> factory</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Server</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">CreateHandler</span></span><span style="color:#000000"><span style="color:#000000">();</span></span>
        <span style="color:#000000"><span style="color:#000000">};</span></span><span style="color:#000000"><span style="color:#000000">
        options</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">WebSocketFactory</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">async</span></span> <span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">context</span></span><span style="color:#000000"><span style="color:#000000">,</span></span><span style="color:#000000"><span style="color:#000000"> token</span></span><span style="color:#000000"><span style="color:#000000">)</span></span> <span style="color:#000000"><span style="color:#000000">=></span></span>
        <span style="color:#000000"><span style="color:#000000">{</span></span>
            <span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> wsClient </span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#000000"><span style="color:#000000"> factory</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Server</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">CreateWebSocketClient</span></span><span style="color:#000000"><span style="color:#000000">();</span></span>
            <span style="color:#1e1eff"><span style="color:#1e1eff">return</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">await</span></span><span style="color:#000000"><span style="color:#000000"> wsClient</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">ConnectAsync</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">context</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Uri</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">default</span></span><span style="color:#000000"><span style="color:#000000">);</span></span>
        <span style="color:#000000"><span style="color:#000000">};</span></span>
    <span style="color:#000000"><span style="color:#000000">})</span></span>
    <span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Build</span></span><span style="color:#000000"><span style="color:#000000">();</span></span></code></span></span>

现在可以使用新的OnCheckSlidingExpiration. 例如,此事件可由需要定期 ping 服务器而不影响身份验证会话的单页应用程序使用。

延迟客户端证书协商

开发人员现在可以通过在. 这仅适用于 HTTP/1.1 连接,因为 HTTP/2 严格禁止延迟证书重新协商。此 API 的调用者必须在请求客户端证书之前缓冲请求正文。ClientCertificateMode.DelayCertificateHttpsConnectionAdapterOptions

<span style="color:#212529"><span style="background-color:#f0f0f0 !important"><code><span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> builder </span></span><span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#660066"><span style="color:#660066">WebApplication</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">CreateBuilder</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">args</span></span><span style="color:#000000"><span style="color:#000000">);</span></span><span style="color:#000000"><span style="color:#000000">
builder</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">WebHost</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">UseKestrel</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">options </span></span><span style="color:#000000"><span style="color:#000000">=></span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span><span style="color:#000000"><span style="color:#000000">
    options</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">ConfigureHttpsDefaults</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">adapterOptions </span></span><span style="color:#000000"><span style="color:#000000">=></span></span>
    <span style="color:#000000"><span style="color:#000000">{</span></span><span style="color:#000000"><span style="color:#000000">
        adapterOptions</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">ClientCertificateMode</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#660066"><span style="color:#660066">ClientCertificateMode</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">DelayCertificate</span></span><span style="color:#000000"><span style="color:#000000">;</span></span>
    <span style="color:#000000"><span style="color:#000000">});</span></span>
<span style="color:#000000"><span style="color:#000000">});</span></span>

<span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> app </span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#000000"><span style="color:#000000"> builder</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Build</span></span><span style="color:#000000"><span style="color:#000000">();</span></span><span style="color:#000000"><span style="color:#000000">
app</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Use</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#1e1eff"><span style="color:#1e1eff">async</span></span> <span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">context</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">next</span></span><span style="color:#000000"><span style="color:#000000">)</span></span> <span style="color:#000000"><span style="color:#000000">=></span></span>
<span style="color:#000000"><span style="color:#000000">{</span></span>
    <span style="color:#008800"><span style="color:#008800">// Check if your desired criteria is met</span></span>
    <span style="color:#1e1eff"><span style="color:#1e1eff">if</span></span> <span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">desiredState </span></span><span style="color:#000000"><span style="color:#000000">==</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">true</span></span><span style="color:#000000"><span style="color:#000000">)</span></span>
    <span style="color:#000000"><span style="color:#000000">{</span></span>
        <span style="color:#008800"><span style="color:#008800">// Buffer the request body</span></span><span style="color:#000000"><span style="color:#000000">
        context</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Request</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">EnableBuffering</span></span><span style="color:#000000"><span style="color:#000000">();</span></span>
        <span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> body </span></span><span style="color:#000000"><span style="color:#000000">=</span></span><span style="color:#000000"><span style="color:#000000"> context</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Request</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Body</span></span><span style="color:#000000"><span style="color:#000000">;</span></span>
        <span style="color:#1e1eff"><span style="color:#1e1eff">await</span></span><span style="color:#000000"><span style="color:#000000"> body</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">DrainAsync</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">context</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">RequestAborted</span></span><span style="color:#000000"><span style="color:#000000">);</span></span><span style="color:#000000"><span style="color:#000000">
        body</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Position</span></span> <span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#006666"><span style="color:#006666">0</span></span><span style="color:#000000"><span style="color:#000000">;</span></span>

        <span style="color:#008800"><span style="color:#008800">// Request client certificate</span></span>
        <span style="color:#1e1eff"><span style="color:#1e1eff">var</span></span><span style="color:#000000"><span style="color:#000000"> cert </span></span><span style="color:#000000"><span style="color:#000000">=</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">await</span></span><span style="color:#000000"><span style="color:#000000"> context</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Connection</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">GetClientCertificateAsync</span></span><span style="color:#000000"><span style="color:#000000">();</span></span>

        <span style="color:#008800"><span style="color:#008800">//  Disable buffering on future requests if the client doesn't provide a cert</span></span>
    <span style="color:#000000"><span style="color:#000000">}</span></span> 
    <span style="color:#1e1eff"><span style="color:#1e1eff">return</span></span> <span style="color:#1e1eff"><span style="color:#1e1eff">next</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#000000"><span style="color:#000000">context</span></span><span style="color:#000000"><span style="color:#000000">);</span></span>
<span style="color:#000000"><span style="color:#000000">});</span></span><span style="color:#000000"><span style="color:#000000">
app</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">MapGet</span></span><span style="color:#000000"><span style="color:#000000">(</span></span><span style="color:#980606"><span style="color:#980606">"/"</span></span><span style="color:#000000"><span style="color:#000000">,</span></span> <span style="color:#000000"><span style="color:#000000">()</span></span> <span style="color:#000000"><span style="color:#000000">=></span></span> <span style="color:#980606"><span style="color:#980606">"Hello World!"</span></span><span style="color:#000000"><span style="color:#000000">);</span></span><span style="color:#000000"><span style="color:#000000">
app</span></span><span style="color:#000000"><span style="color:#000000">.</span></span><span style="color:#660066"><span style="color:#660066">Run</span></span><span style="color:#000000"><span style="color:#000000">();</span></span></code></span></span>

给予反馈

我们希望您喜欢 .NET 6 中 ASP.NET Core 的这个预览版本。我们很想知道您对这个版本的体验。通过在GitHub 上提交问题让我们知道您的想法。

感谢您试用 ASP.NET Core!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值