From 6d9b1468ce1e24d6395b1b9178e63bd1cb15eac2 Mon Sep 17 00:00:00 2001 From: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> Date: Thu, 29 Jul 2021 13:10:05 -0700 Subject: [PATCH] Update http-context.md (#22698) * Update http-context.md * Update aspnetcore/fundamentals/http-context.md * Update http-context.md * Update http-context.md * Update aspnetcore/fundamentals/http-context.md * Update aspnetcore/fundamentals/http-context.md Co-authored-by: Kirk Larkin Co-authored-by: Kirk Larkin --- aspnetcore/fundamentals/http-context.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aspnetcore/fundamentals/http-context.md b/aspnetcore/fundamentals/http-context.md index d6aeaa3ffa..17af5fa6ad 100644 --- a/aspnetcore/fundamentals/http-context.md +++ b/aspnetcore/fundamentals/http-context.md @@ -1,7 +1,7 @@ --- title: Access HttpContext in ASP.NET Core author: coderandhiker -description: Learn how to access HttpContext in ASP.NET Core. +description: HttpContext in ASP.NET Core. HttpContext is not thread-safe and can throw NullReferenceException. monikerRange: '>= aspnetcore-2.1' ms.author: riande ms.custom: mvc @@ -138,6 +138,7 @@ To safely perform background work with `HttpContext` data: * Copy the required data during request processing. * Pass the copied data to a background task. +* Do ***not*** reference `HttpContext` data in parallel tasks. Extract the data needed from the context before starting the parallel tasks. To avoid unsafe code, never pass the `HttpContext` into a method that performs background work. Pass the required data instead. In the following example, `SendEmailCore` is called to start sending an email. The `correlationId` is passed to `SendEmailCore`, not the `HttpContext`. Code execution doesn't wait for `SendEmailCore` to complete: