PROPERTY

HttpContext.RequestAborted

A token indicating that the HTTP request was aborted. Pass it into downstream cancellable work; cancellation is cooperative and does not roll back already committed effects. Requires ASP.NET Core.

Formal Syntax & Structure

csharp syntaxcsharp
CancellationToken token = context.RequestAborted;

Working Example

Example Snippetcsharp
using System;using System.IO;using System.Collections.Generic;using System.Net;using System.Net.Http;using System.Net.Http.Headers;using System.Threading;using Microsoft.AspNetCore.Http;using var cts = new CancellationTokenSource();var context = new DefaultHttpContext { RequestAborted = cts.Token };cts.Cancel();Console.WriteLine(context.RequestAborted.IsCancellationRequested); // True
C# & .NET Reference