Prep monikers for V6 (#24255)
parent
7e83f8da38
commit
3353a3ada5
|
@ -15,7 +15,7 @@ uid: fundamentals/index
|
|||
|
||||
This article provides an overview of key topics for understanding how to develop ASP.NET Core apps.
|
||||
|
||||
## The Startup class
|
||||
## Program.cs
|
||||
|
||||
The `Startup` class is where:
|
||||
|
||||
|
@ -26,7 +26,6 @@ Here's a sample `Startup` class:
|
|||
|
||||
[!code-csharp[](index/samples_snapshot/3.x/Startup.cs?highlight=3,12)]
|
||||
|
||||
For more information, see <xref:fundamentals/startup>.
|
||||
|
||||
## Dependency injection (services)
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
title: Response Caching Middleware in ASP.NET Core
|
||||
author: rick-anderson
|
||||
description: Learn how to configure and use Response Caching Middleware in ASP.NET Core.
|
||||
monikerRange: '>= aspnetcore-2.1'
|
||||
monikerRange: '>= aspnetcore-3.1'
|
||||
ms.author: riande
|
||||
ms.custom: mvc
|
||||
ms.date: 02/07/2020
|
||||
ms.date: 12/07/2021
|
||||
no-loc: [Home, Privacy, Kestrel, appsettings.json, "ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR]
|
||||
uid: performance/caching/middleware
|
||||
---
|
||||
|
@ -13,7 +13,7 @@ uid: performance/caching/middleware
|
|||
|
||||
By [John Luo](https://github.com/JunTaoLuo)
|
||||
|
||||
::: moniker range=">= aspnetcore-3.0"
|
||||
::: moniker range=">= aspnetcore-6.0"
|
||||
|
||||
This article explains how to configure Response Caching Middleware in an ASP.NET Core app. The middleware determines when responses are cacheable, stores responses, and serves responses from cache. For an introduction to HTTP caching and the [`[ResponseCache]`](xref:Microsoft.AspNetCore.Mvc.ResponseCacheAttribute) attribute, see [Response Caching](xref:performance/caching/response).
|
||||
|
||||
|
@ -160,7 +160,7 @@ When testing and troubleshooting caching behavior, a browser may set request hea
|
|||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="< aspnetcore-3.0"
|
||||
::: moniker range="< aspnetcore-6.0"
|
||||
|
||||
This article explains how to configure Response Caching Middleware in an ASP.NET Core app. The middleware determines when responses are cacheable, stores responses, and serves responses from cache. For an introduction to HTTP caching and the [`[ResponseCache]`](xref:Microsoft.AspNetCore.Mvc.ResponseCacheAttribute) attribute, see [Response Caching](xref:performance/caching/response).
|
||||
|
||||
|
@ -168,22 +168,25 @@ This article explains how to configure Response Caching Middleware in an ASP.NET
|
|||
|
||||
## Configuration
|
||||
|
||||
Use the [Microsoft.AspNetCore.App metapackage](xref:fundamentals/metapackage-app) or add a package reference to the [Microsoft.AspNetCore.ResponseCaching](https://www.nuget.org/packages/Microsoft.AspNetCore.ResponseCaching/) package.
|
||||
Response Caching Middleware is implicitly available for ASP.NET Core apps via the shared framework.
|
||||
|
||||
In `Startup.ConfigureServices`, add the Response Caching Middleware to the service collection:
|
||||
|
||||
[!code-csharp[](middleware/samples/2.x/ResponseCachingMiddleware/Startup.cs?name=snippet1&highlight=3)]
|
||||
[!code-csharp[](middleware/samples/3.x/ResponseCachingMiddleware/Startup.cs?name=snippet1&highlight=3)]
|
||||
|
||||
Configure the app to use the middleware with the <xref:Microsoft.AspNetCore.Builder.ResponseCachingExtensions.UseResponseCaching*> extension method, which adds the middleware to the request processing pipeline in `Startup.Configure`:
|
||||
|
||||
[!code-csharp[](middleware/samples/2.x/ResponseCachingMiddleware/Startup.cs?name=snippet2&highlight=14)]
|
||||
[!code-csharp[](middleware/samples/3.x/ResponseCachingMiddleware/Startup.cs?name=snippet2&highlight=17)]
|
||||
|
||||
> [!WARNING]
|
||||
> <xref:Microsoft.AspNetCore.Builder.CorsMiddlewareExtensions.UseCors%2A> must be called before <xref:Microsoft.AspNetCore.Builder.ResponseCachingExtensions.UseResponseCaching%2A> when using [CORS middleware](xref:security/cors).
|
||||
|
||||
The sample app adds headers to control caching on subsequent requests:
|
||||
|
||||
* [Cache-Control](https://tools.ietf.org/html/rfc7234#section-5.2): Caches cacheable responses for up to 10 seconds.
|
||||
* [Vary](https://tools.ietf.org/html/rfc7231#section-7.1.4): Configures the middleware to serve a cached response only if the [Accept-Encoding](https://tools.ietf.org/html/rfc7231#section-5.3.4) header of subsequent requests matches that of the original request.
|
||||
|
||||
[!code-csharp[](middleware/samples_snippets/2.x/AddHeaders.cs)]
|
||||
[!code-csharp[](middleware/samples_snippets/3.x/AddHeaders.cs)]
|
||||
|
||||
The preceding headers are not written to the response and are overridden when a controller, action, or Razor Page:
|
||||
|
||||
|
@ -302,4 +305,4 @@ When testing and troubleshooting caching behavior, a browser may set request hea
|
|||
* <xref:mvc/views/tag-helpers/builtin-th/cache-tag-helper>
|
||||
* <xref:mvc/views/tag-helpers/builtin-th/distributed-cache-tag-helper>
|
||||
|
||||
::: moniker-end
|
||||
::: moniker-end
|
||||
|
|
Loading…
Reference in New Issue