Cookie Consent Manager

The Cookie Consent system provides GDPR-compliant cookie consent management with FodCookieBanner (with inline expandable settings), IFodConsentService integration, and full localization support (English, Romanian).

Current Consent State

Display the current consent status and accepted categories.

Consent Required

True

Necessary

True

Statistics

False

Marketing

False

Preferences

False

FodCookieBanner

The cookie banner is placed in MainLayout and automatically shows when consent is required. Click 'Show Banner' to trigger it by revoking consent.

razor
<FodCookieBanner
    Position="BannerPosition.Bottom"
    PrivacyPolicyUrl="/privacy"
    CookiePolicyUrl="/cookie-policy" />

IFodConsentService Methods

Use IFodConsentService to programmatically manage consent state.

Accept all categories

Accept necessary only

Custom consent

Revoke consent

csharp
@inject IFodConsentService ConsentService

// Accept all categories
ConsentService.AcceptAll();

// Accept only necessary cookies
ConsentService.AcceptNecessaryOnly();

// Custom consent selection
ConsentService.UpdateConsent(
    ConsentCategory.Necessary | ConsentCategory.Statistics | ConsentCategory.Marketing
);

// Revoke all consent (triggers banner to show)
ConsentService.RevokeConsent();

// Check if category is accepted
bool isAccepted = ConsentService.Current.IsCategoryAccepted(ConsentCategory.Marketing);

OnConsentChanged Event

Subscribe to the OnConsentChanged event to react to consent state changes.

csharp
protected override void OnInitialized()
{
    ConsentService.OnConsentChanged += HandleConsentChanged;
}

private void HandleConsentChanged(ConsentChangedEventArgs args)
{
    // args.Reason: User, Initialization, Expiration, Revocation
    // args.Current.AcceptedCategories: The new consent categories
    InvokeAsync(StateHasChanged);
}

public void Dispose()
{
    ConsentService.OnConsentChanged -= HandleConsentChanged;
}

Usage

How to set up and use the Cookie Consent system in your application.

1. Register Services

csharp
// Program.cs
builder.Services.AddFod(options =>
{
    options.ConsentOptions.PrivacyPolicyUrl = "/privacy";
    options.ConsentOptions.CookiePolicyUrl = "/cookie-policy";
    options.ConsentOptions.ExpirationMonths = 12;
});

2. Configure Options

csharp
builder.Services.AddFod(options =>
{
    options.ConsentOptions.CookieName = "my_consent";
    options.ConsentOptions.ExpirationMonths = 6;
    options.ConsentOptions.PrivacyPolicyUrl = "/privacy";
    options.ConsentOptions.CookiePolicyUrl = "/cookies";
    options.ConsentOptions.EnableGoogleConsentMode = true;
    options.ConsentOptions.EnableScriptBlocking = true;
    options.ConsentOptions.ConsentVersion = 1;
});

3. Add FodCookieBanner to Layout

razor
<FodCookieBanner
    Position="BannerPosition.Bottom"
    PrivacyPolicyUrl="/privacy"
    CookiePolicyUrl="/cookie-policy" />

Localization

FodCookieBanner is fully localized using IStringLocalizer. All text content uses resource files that can be extended for additional languages.

Supported Languages

  • English (en) - Default language
  • Romanian (ro) - Full translation

Localization Keys

No properties defined.

Customizing Text via Parameters

You can override any localized text using component parameters. Parameter values take precedence over localized strings.

razor
<!-- Override localized text with custom values -->
<FodCookieBanner
    AcceptAllText="Accept Cookies"
    NecessaryOnlyText="Essential Only"
    ManageCookiesText="Cookie Settings"
    PrivacyPolicyText="View Privacy Policy"
    CookiePolicyText="View Cookie Policy" />

Accessibility Features

Cookie consent components provide WCAG 2.1 AA compliant accessibility features.

ARIA Attributes

  • role="region" - Identifies the banner as a landmark region
  • aria-label - Provides accessible name for the banner
  • aria-describedby - Links banner to its description text
  • aria-expanded - Indicates expandable settings section state
  • aria-controls - Links toggle button to settings content

Keyboard Navigation

  • Tab - Navigate between buttons and controls
  • Enter / Space - Activate focused button or toggle settings

API Reference

FodCookieBanner and IFodConsentService API documentation.

FodCookieBanner Parameters

No properties defined.

IFodConsentService Members

No properties defined.

ConsentCategory Enum

No properties defined.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.