Soenneker.Blazor.Turnstile 4.0.2896

Prefix Reserved
dotnet add package Soenneker.Blazor.Turnstile --version 4.0.2896
                    
NuGet\Install-Package Soenneker.Blazor.Turnstile -Version 4.0.2896
                    
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="Soenneker.Blazor.Turnstile" Version="4.0.2896" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Blazor.Turnstile" Version="4.0.2896" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Blazor.Turnstile" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Blazor.Turnstile --version 4.0.2896
                    
#r "nuget: Soenneker.Blazor.Turnstile, 4.0.2896"
                    
#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.
#:package Soenneker.Blazor.Turnstile@4.0.2896
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Blazor.Turnstile&version=4.0.2896
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Blazor.Turnstile&version=4.0.2896
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Blazor.Turnstile

Renders a Cloudflare Turnstile widget in Blazor and exposes its token, expiration, error, reset, and removal lifecycle.

Installation

dotnet add package Soenneker.Blazor.Turnstile

Registration

using Soenneker.Blazor.Turnstile.Registrars;

builder.Services.AddTurnstileInteropAsScoped();

Render a widget

@using Soenneker.Blazor.Turnstile
@using Soenneker.Blazor.Turnstile.Options

<Turnstile Options="_options"
           OnCallback="HandleToken"
           OnExpiredCallback="HandleExpiration"
           OnErrorCallback="HandleError" />

@code {
    private readonly TurnstileOptions _options = new()
    {
        SiteKey = "your-site-key",
        Action = "sign-in"
    };

    private Task HandleToken(string token)
    {
        if (!string.IsNullOrEmpty(token))
        {
            // Send the token to a trusted server for Siteverify validation.
        }

        return Task.CompletedTask;
    }

    private Task HandleExpiration(string _) => Task.CompletedTask;
    private Task HandleError(string message) => Task.CompletedTask;
}

OnCallback and TokenChanged are raised when a token is issued and again with a cleared value after expiration or an error. OnExpiredCallback and OnErrorCallback provide the corresponding reason. The component's Token and WidgetId properties expose the current values.

The browser token is not proof that a request is legitimate. Send it to a trusted server and validate it with Cloudflare's Siteverify API before performing the protected operation. Keep the Turnstile secret on the server; never include it in Blazor WebAssembly code or browser configuration.

Manual lifecycle

Set ManualCreate = true when application code needs to control widget creation. After the component has rendered, call Create() and retain its returned widget ID. With automatic creation, use Reset() to request another challenge and Remove() to remove the JavaScript widget.

<Turnstile @ref="_turnstile" Options="_manualOptions" />

@code {
    private Turnstile? _turnstile;

    private readonly TurnstileOptions _manualOptions = new()
    {
        SiteKey = "your-site-key",
        ManualCreate = true
    };

    private async Task CreateWidget()
    {
        if (_turnstile is not null)
            await _turnstile.Create();
    }
}

Calling Create() before the component's first render throws InvalidOperationException. Calling it again without first removing the widget returns null. The component disposes its .NET reference when it leaves the render tree; the scoped interop service is owned by dependency injection.

See Cloudflare's client-side rendering documentation for supported widget settings and the Siteverify documentation for server validation.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
4.0.2896 49 9/26/2026
4.0.2895 54 9/25/2026
4.0.2894 41 9/25/2026
4.0.2893 42 9/25/2026
4.0.2892 39 9/25/2026
4.0.2891 40 9/25/2026
4.0.2890 32 9/25/2026
4.0.2889 56 9/25/2026
4.0.2888 42 9/25/2026
4.0.2887 46 9/25/2026
4.0.2885 46 9/24/2026
4.0.2883 44 9/24/2026
4.0.2882 38 9/24/2026
4.0.2881 60 9/24/2026
4.0.2880 299 9/16/2026
4.0.2878 123 9/16/2026
4.0.2876 91 9/16/2026
4.0.2875 98 9/16/2026
4.0.2874 104 9/16/2026
4.0.2872 92 9/16/2026
Loading failed

Updated Soenneker.Utils.Json to 4.0.2725