Skip to content

Commit 90d0d0b

Browse files
authored
Add Blazor to lists of app types (#34368)
1 parent 481d522 commit 90d0d0b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

aspnetcore/fundamentals/use-http-context.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: jamesnk
44
description: How to use HttpContext in ASP.NET Core.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
7-
ms.date: 10/07/2024
7+
ms.date: 12/13/2024
88
uid: fundamentals/use-httpcontext
99
---
1010
<!-- ms.sfi.ropc: t -->
@@ -13,9 +13,7 @@ uid: fundamentals/use-httpcontext
1313

1414
[!INCLUDE[](~/includes/not-latest-version.md)]
1515

16-
<xref:Microsoft.AspNetCore.Http.HttpContext> encapsulates all information about an individual HTTP request and response. An `HttpContext` instance is initialized when an HTTP request is received. The `HttpContext` instance is accessible by middleware and app frameworks such as Web API controllers, Razor Pages, SignalR, gRPC, and more.
17-
18-
For more information about accessing the `HttpContext`, see <xref:fundamentals/httpcontext>.
16+
<xref:Microsoft.AspNetCore.Http.HttpContext> encapsulates all information about an individual HTTP request and response. An `HttpContext` instance is initialized when an HTTP request is received. The `HttpContext` instance is accessible by middleware and app frameworks such as Blazor Web Apps, Web API controllers, Razor Pages, SignalR, gRPC, and more.
1917

2018
## `HttpRequest`
2119

@@ -97,7 +95,7 @@ Commonly used members on `HttpResponse` include:
9795
<xref:Microsoft.AspNetCore.Http.HttpResponse.Headers?displayProperty=nameWithType> provides access to the response headers sent with the HTTP response. There are two ways to access headers using this collection:
9896

9997
* Provide the header name to the indexer on the header collection. The header name isn't case-sensitive. The indexer can access any header value.
100-
* The header collection also has properties for getting and setting commonly used HTTP headers. The properties provide a fast, IntelliSense driven way to access headers.
98+
* Use the header collection properties for getting and setting commonly used HTTP headers. The properties provide a fast, IntelliSense driven way to access headers.
10199

102100
[!code-csharp[](use-http-context/samples/Program.cs?name=snippet_ResponseHeaders&highlight=6-7)]
103101

@@ -182,13 +180,13 @@ For more information about using request features and `HttpContext`, see <xref:f
182180

183181
## HttpContext isn't thread safe
184182

185-
This article primarily discusses using `HttpContext` in request and response flow from Razor Pages, controllers, middleware, etc. Consider the following when using `HttpContext` outside the request and response flow:
183+
This article primarily discusses using `HttpContext` in request and response flow from Blazor Web App components, Razor Pages, controllers, middleware, and so forth. Consider the following when using `HttpContext` outside the request and response flow:
186184

187-
* The `HttpContext` is **NOT** thread safe, accessing it from multiple threads can result in exceptions, data corruption and generally unpredictable results.
188-
* The <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> interface should be used with caution. As always, the `HttpContext` must ***not*** be captured outside of the request flow. `IHttpContextAccessor`:
189-
* Relies on <xref:System.Threading.AsyncLocal%601> which can have a negative performance impact on asynchronous calls.
185+
* The `HttpContext` is **NOT** thread safe. Accessing it from multiple threads can result in unpredictable results, such as exceptions and data corruption.
186+
* The <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor> interface should be used with caution. As always, the `HttpContext` must ***not*** be captured outside of the request flow. `IHttpContextAccessor`:
187+
* Relies on <xref:System.Threading.AsyncLocal%601>, which can have a negative performance impact on asynchronous calls.
190188
* Creates a dependency on "ambient state" which can make testing more difficult.
191-
* <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor.HttpContext%2A?displayProperty=nameWithType> may be `null` if accessed outside of the request flow.
189+
* <xref:Microsoft.AspNetCore.Http.IHttpContextAccessor.HttpContext%2A?displayProperty=nameWithType> might be `null` if accessed outside of the request flow.
192190
* To access information from `HttpContext` outside the request flow, copy the information inside the request flow. Be careful to copy the actual data and not just references. For example, rather than copying a reference to an `IHeaderDictionary`, copy the relevant header values or copy the entire dictionary key by key before leaving the request flow.
193191
* Don't capture `IHttpContextAccessor.HttpContext` in a constructor.
194192

@@ -219,3 +217,7 @@ The application also includes `PeriodicBranchesLoggerService`, which logs the op
219217
`PeriodicBranchesLoggerService` is a [hosted service](xref:fundamentals/host/hosted-services), which runs outside the request and response flow. Logging from the `PeriodicBranchesLoggerService` has a null `HttpContext`. The `PeriodicBranchesLoggerService` was written to not depend on the `HttpContext`.
220218

221219
[!code-csharp[](~/fundamentals/http-context/samples/6.x/HttpContextInBackgroundThread/Program.cs?highlight=8&range=1-11)]
220+
221+
## Additional resources
222+
223+
For more information about accessing `HttpContext`, see <xref:fundamentals/httpcontext>.

0 commit comments

Comments
 (0)