Pacem.Mvc.CookiePolicy 0.8.10-euler

This is a prerelease version of Pacem.Mvc.CookiePolicy.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Pacem.Mvc.CookiePolicy --version 0.8.10-euler
                    
NuGet\Install-Package Pacem.Mvc.CookiePolicy -Version 0.8.10-euler
                    
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="Pacem.Mvc.CookiePolicy" Version="0.8.10-euler" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pacem.Mvc.CookiePolicy" Version="0.8.10-euler" />
                    
Directory.Packages.props
<PackageReference Include="Pacem.Mvc.CookiePolicy" />
                    
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 Pacem.Mvc.CookiePolicy --version 0.8.10-euler
                    
#r "nuget: Pacem.Mvc.CookiePolicy, 0.8.10-euler"
                    
#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 Pacem.Mvc.CookiePolicy@0.8.10-euler
                    
#: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=Pacem.Mvc.CookiePolicy&version=0.8.10-euler&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Pacem.Mvc.CookiePolicy&version=0.8.10-euler&prerelease
                    
Install as a Cake Tool

About

Pacem.Mvc.CookiePolicy provides a lightweight middleware that helps to filter unconsented cookies according to European (GDPR) policies.

The following paragraphs exemplify the library utilization.

Getting started

Add required services and middlewares.

Like this:

// Program.cs

// services
services.AddPacemCookiePolicy(options => {
    // specify cookie sets and their category, e.g.:
    options.Necessary = ["Pacem/Pacem", Known1stPartyCookieSets.Azure /* ARRAffinity, ARRAffinitySameSite */];
    options.Functional = [Known3rdPartyCookieSets.GoogleYouTube];
    options.Performance = [Known3rdPartyCookieSets.GoogleAnalytics];
    options.Marketing = [Known3rdPartyCookieSets.GoogleAdSense];
});

// middleware
app.UsePacemCookiePolicy();

As you can see, a few (very few) of the most known CookieSets are available out of the box.

A CookieSet is a string formatted like {Provider}/{Product}.
Example: Google/YouTube.
It identifies a manifest (CookieProvider) that groups a set of cookies relevant to the specific Product.

If you need to include some other ones, configure them:


services.AddPacemCookiePolicy(options => {
    // custom cookie set
    options.Necessary = ["MyCompany/WebApp"];
    // ...
}).WithCustomCookieProviders(providerName => {
    if (providerName == "MyCompany")
    {
        // TODO: factory custom cookie provider 
        // with relevant product 'WebApp'...
    }
});

The Provided/Opinionated Way

Requests to the server using the specific headers X-Pacem-CookieConsent and X-Pacem-CookieRevoke are designed to manage cookieset consents and revocations respectively:

Consent:

GET: /.pacem-cookies HTTP/1.1
X-Pacem-CookieConsent: Google/YouTube

Revoke:

GET: /.pacem-cookies HTTP/1.1
X-Pacem-CookieRevoke: Google/YouTube

Any url goes for this purpose. However, /.pacem-cookies is a peculiar path: its response returns the current, up-to-date and json-formatted, cookie configuration.

// example of a response from '/.pacem-cookies'
{
    // all the configured cookie sets to manage, grouped by category
    "managedCookieSets": {
        "necessary":[
            { 
                "provider": "MyCompany",
                "products": [
                    {
                        "name": "MyApp",
                        "set": {
                            "product": "MyApp",
                            "value": "MyCompany/MyApp",
                            "provider": "MyCompany",
                        },
                        "cookies": [
                            {
                                "name": "_mycomp.tracker",
                                "duration": {
                                    "duration": "1 year",
                                    "value": 1,
                                    "unit": "year"
                                },
                                "type": 0 // 0: Cookie, 1: LocalStorage, 2: Pixel
                                "description": "..."
                            },
                            // ...other 'MyApp' cookies
                        ],
                    },
                    // ...other 'MyCompany' products
                ]
            },
            // ...other 'necessary' providers
        ],
        "performance":[
            // ...'performance' providers
        ],
        "functional":[
            // ...'functional' providers
        ],
        "marketing":[
            // ...'marketing' providers
        ],
        "other":[
            // ...'other' providers
        ]
    },
    // all the consented cookie sets
    "consentedCookieSets": ["Pacem/Pacem", "MyCompany/WebApp"],
    // all the consented cookies
    "consentedCookieNames": [".pacem.cookieconsent", "_mycomp.tracker"],
}

Header-valued requests act atomically: each request adds or removes only the specified set of cookies, which can be comma-concatenated if necessary.

The Custom Way

You are free to manage consents and revocations in any less-opinionated way, as long as you lean on the ICookiePolicyService service, which is available among the injected DI services:

public interface ICookiePolicyService
{
    void Consent(CookieSet cookieSet);
    void Revoke(CookieSet cookieSet);
    void RevokeAll();
    IEnumerable<CookieSet> GetConsentedCookieSets();
}

Methods are self-explanatory.

Not only this library's middlewares intercept proprietary cookie in responses, they may also help in managing some 3rd party contents.

Google Tag Manager

Strictly relevant to the provided implementation, a convenient TagHelper comes along to safely include Google's TagManager:


<script pacem-google-tag="my-Google-tag-ID" />

This very same TagHelper also injects some utility methods into the DOM. Example:

// JavaScript utility method that pushes path navigation:
/* window.*/Pacem.Utils.GoogleTag.push('/path');
// ...or any other event standard or custom:
/* window.*/Pacem.Utils.GoogleTag.push('event', 'subscribed', { channel: 'Blog 1', userId: 42});
/* window.*/Pacem.Utils.GoogleTag.push({ event: 'event', method: 'subscribed', channel: 'Blog 1', userId: 42});

Google Tag functionalities depend on the given consent provided by the middleware responses.
By default, they are switched off.

Google Tag Manager scripts are added to the page only after the user's consent.

Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on Pacem.Mvc.CookiePolicy:

Package Downloads
Pacem.Mvc.TagHelpers

TagHelpers for Razor AspNet.Core web applications in Pacem Ecosystem.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.0-dirac 46 8/2/2025
0.9.0-cayley 90 7/31/2025
0.9.0-boyle 90 7/31/2025
0.9.0-abel 113 7/17/2025
0.8.11 156 5/27/2025
0.8.10 172 5/7/2025
0.8.10-fourier 102 5/2/2025
0.8.10-fibonacci 98 2/7/2025
0.8.10-fermat 191 2/3/2025
0.8.10-euler 101 2/3/2025
0.8.10-euclid 113 2/1/2025
0.8.10-dalembert 99 1/31/2025
0.8.10-cauchy 119 1/26/2025
0.8.10-cantor 111 12/18/2024
0.8.10-caccioppoli 110 12/6/2024
0.8.10-bourbaki 104 12/6/2024
0.8.10-abel 128 4/22/2024
0.8.6 170 3/17/2024
0.8.6-abel 113 3/14/2024
0.8.5 166 3/13/2024
0.8.4 178 3/12/2024
0.8.3 142 3/12/2024
0.8.2 153 3/11/2024
0.8.1 134 3/11/2024
0.8.0 188 2/4/2024
0.8.0-akkad 225 12/8/2023
0.7.4 253 11/20/2023
0.7.3 181 11/17/2023
0.7.2 162 11/16/2023
0.7.2-atlantis 161 11/16/2023
0.7.1 173 11/15/2023
0.7.0-cumae 184 8/26/2023
0.7.0-corcyra 217 8/17/2023
0.7.0-byzantium 180 8/16/2023
0.7.0-bithynia 203 7/26/2023
0.7.0-baalbek 203 7/24/2023
0.7.0-atlantis 443 10/1/2020
0.6.0 1,055 4/12/2020
0.5.4 1,093 8/29/2019
0.5.3 1,176 12/4/2018
0.5.2 1,170 11/30/2018
0.5.1 1,167 11/27/2018
0.5.0 1,245 11/21/2018
0.4.1 1,259 11/2/2018
0.4.0 1,295 10/22/2018