HttpContextCatcher 8.4.0

dotnet add package HttpContextCatcher --version 8.4.0                
NuGet\Install-Package HttpContextCatcher -Version 8.4.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HttpContextCatcher" Version="8.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HttpContextCatcher --version 8.4.0                
#r "nuget: HttpContextCatcher, 8.4.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HttpContextCatcher as a Cake Addin
#addin nuget:?package=HttpContextCatcher&version=8.4.0

// Install HttpContextCatcher as a Cake Tool
#tool nuget:?package=HttpContextCatcher&version=8.4.0                

HttpContextCatcher

The HttpContextCatcher is an ASP.NET Core middleware that provides an easy and flexible way to intercept and work with the HTTP context asynchronously. It is designed to integrate seamlessly with the ASP.NET Core pipeline, offering a straightforward approach to access request and response data for logging, analysis, or any custom processing needs.

Features

  • Asynchronous Context Processing: Handle your HTTP context without affecting the request-response lifecycle.
  • Dependency Injection Friendly: Works with ASP.NET Core's built-in dependency injection. Inject any registered service into your custom catcher services.
  • Configurable: Choose to ignore certain requests or responses based on custom logic.
  • Easy Integration: Minimal setup required to add to your existing ASP.NET Core applications.
  • Customizable Catcher Services: Implement the IAsyncCatcherService interface to define your own logic for what happens when the HTTP context is captured.

Getting Started

To use HttpContextCatcher in your project, follow these simple steps:

Installation

dotnet add package HttpContextCatcher

Configuration

In your Program.cs, register HttpContextCatcher services:

var builder = WebApplication.CreateBuilder(args);

// Add services to the container
builder.Services.AddHttpContextCatcher(options =>
{
    options.SetCatcher<MyCatcherService>();
    // options.IgnoreRequest(); (Optional)
    // options.IgnoreResponse(); (Optional)
});

builder.Services.AddSingleton<DatabaseAccessor>(); // If your catcher requires it

var app = builder.Build();

// Configure the HTTP request pipeline
app.UseHttpContextCatcher(); // Use the HttpContextCatcher middleware

// Other middleware configurations
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();

app.Run();

Implement your custom catcher service by inheriting from IAsyncCatcherService:

using HttpContextCatcher.CatcherManager;

// In your custom catcher service, you can inject any service that's registered with the DI container
public class MyCatcherService : IAsyncCatcherService
{
    private readonly DatabaseAccessor _databaseAccessor;

    public MyCatcherService(DatabaseAccessor databaseAccessor)
    {
        _databaseAccessor = databaseAccessor;
    }

    public async Task OnCatchAsync(ContextCatcher contextCatcher)
    {
        // Your logic to handle the caught context
        _databaseAccessor.Write(contextCatcher);
    }
}

Support or Contact

Having trouble with HttpContextCatcher? Please email us at r05221017@gmail.com and we'll help you sort it out.

FAQ

Q: How do I ignore specific requests? A: Use the IgnoreRequest method in the options while configuring the service to specify the conditions under which a request should be ignored.

Q: Is it possible to use HttpContextCatcher for response logging? A: Absolutely! Implement the OnCatchAsync method in your catcher service to process the response context as required.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on HttpContextCatcher:

Package Downloads
HttpContextCatcher.Extension

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.4.0 470 8/29/2024
8.3.0 168 8/21/2024
8.2.0 179 8/16/2024
8.1.0 156 8/16/2024
8.0.0 183 8/15/2024
5.0.0 351 10/3/2023
4.0.0 1,687 3/22/2023