Method AddCloudflareForwarding
AddCloudflareForwarding(IServiceCollection, Action<CloudflareForwardingOptions>?)
Registers the services that trust the client address and scheme forwarded by Cloudflare, including a hosted service that keeps Cloudflare's IP ranges up to date. Add the middleware with UseCloudflareForwarding(IApplicationBuilder).
Declaration
public static IServiceCollection AddCloudflareForwarding(this IServiceCollection services, Action<CloudflareForwardingOptions>? configure = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceCollection | services | The service collection to add the services to. |
| Action<CloudflareForwardingOptions> | configure | An optional action to configure options. SavedRangesPath must be set, here or through configuration. |
Returns
| Type | Description |
|---|---|
| IServiceCollection |
Remarks
The application fails to start if SavedRangesPath is not set.
Cloudflare's IP ranges are downloaded when the application starts (in WebApplication apps, before it accepts requests), saved to SavedRangesPath, and downloaded again every RefreshInterval. Startup
waits for the ranges no longer than DownloadTimeout. If they cannot be downloaded in time, the saved
copy is used. Without a usable saved copy, the application still starts, and the middleware refuses every request with a 503 Service
Unavailable response until a download succeeds.
If DownloadRanges is false, the ranges are read from the saved copy instead, at startup and every RefreshInterval. Until it can be read, the middleware refuses every request in the same way.
Downloads use the HttpClient named HttpClientName.