Altairis.Services.Cloudflare 1.0.0

dotnet add package Altairis.Services.Cloudflare --version 1.0.0                
NuGet\Install-Package Altairis.Services.Cloudflare -Version 1.0.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="Altairis.Services.Cloudflare" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Altairis.Services.Cloudflare --version 1.0.0                
#r "nuget: Altairis.Services.Cloudflare, 1.0.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 Altairis.Services.Cloudflare as a Cake Addin
#addin nuget:?package=Altairis.Services.Cloudflare&version=1.0.0

// Install Altairis.Services.Cloudflare as a Cake Tool
#tool nuget:?package=Altairis.Services.Cloudflare&version=1.0.0                

Altairis.Services.Cloudflare

Cloudflare proxy support for ASP.NET Core

Cloudlfare is a popular service providing (among others) reverse proxy/CDN services. That means that the web server is hidden behind Cloudflare's servers and does not have direct access to client IP address.

ASP.NET Core has a solution for this: the Forwarded Headers Middleware, which can read X-Forwarded-For and similar headers and set HttpContext.Connection.RemoteIpAddress property accordingly.

For these two to work together, one needs to set properly IP ranges of known networks, as published by Cloudflare. This library automates this process, by downloading list of IPv4 and IPv6 ranges and applying them.

Basic usage

First, install the Altairis.Services.Cloudflare package.

Then, in your Program.cs, call the UseCloudflare method. This is the minimal sample application:

using Altairis.Services.Cloudflare;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

// Configure to use Cloudflare proxy
app.UseCloudflare();

// Show assumed client IP
app.MapGet("/", (HttpContext context) => context.Connection?.RemoteIpAddress?.ToString());

// Run application
app.Run();

Advanced usage

You may use the static method CloudflareForwardedHeadersConfigurator.GetForwardedHeadersOptions to get ForwardedHeadersOptions class configured for CloudFlare and then configure the Forwarded Headers Middleware yourself.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 845 9/4/2022