Pacem.Mvc.CookiePolicy 0.9.14

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Pacem.Mvc.CookiePolicy --version 0.9.14
                    
NuGet\Install-Package Pacem.Mvc.CookiePolicy -Version 0.9.14
                    
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.9.14" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pacem.Mvc.CookiePolicy" Version="0.9.14" />
                    
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.9.14
                    
#r "nuget: Pacem.Mvc.CookiePolicy, 0.9.14"
                    
#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.9.14
                    
#: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.9.14
                    
Install as a Cake Addin
#tool nuget:?package=Pacem.Mvc.CookiePolicy&version=0.9.14
                    
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 net9.0 is compatible.  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.10.0-descartes 83 1/19/2026
0.10.0-cramer 86 1/13/2026
0.10.0-cotes 86 1/13/2026
0.10.0-clapeyron 81 1/12/2026
0.10.0-cauchy 85 1/12/2026
0.10.0-boyle 87 12/30/2025
0.10.0-abel 187 12/4/2025
0.9.14 573 12/1/2025
0.9.14-debroglie 176 11/26/2025
0.9.14-cantor 174 11/24/2025
0.9.14-bourbaki 173 11/24/2025
0.9.14-abel 147 11/23/2025
0.9.13 152 11/15/2025
0.9.12 156 11/15/2025
0.9.11 169 11/15/2025
0.9.1 181 10/23/2025
0.9.0 122 10/11/2025
0.9.0-fermi 173 9/29/2025
0.9.0-erlang 312 9/17/2025
0.9.0-dirac 80 8/2/2025
0.9.0-cayley 124 7/31/2025
0.9.0-boyle 125 7/31/2025
0.9.0-abel 164 7/17/2025
0.8.11 200 5/27/2025
0.8.10 217 5/7/2025
0.8.10-fourier 133 5/2/2025
0.8.10-fibonacci 128 2/7/2025
0.8.10-fermat 243 2/3/2025
0.8.10-euler 131 2/3/2025
0.8.10-euclid 144 2/1/2025
0.8.10-dalembert 131 1/31/2025
0.8.10-cauchy 143 1/26/2025
0.8.10-cantor 144 12/18/2024
0.8.10-caccioppoli 143 12/6/2024
0.8.10-bourbaki 141 12/6/2024
0.8.10-abel 161 4/22/2024
0.8.6 215 3/17/2024
0.8.6-abel 146 3/14/2024
0.8.5 212 3/13/2024
0.8.4 226 3/12/2024
0.8.3 187 3/12/2024
0.8.2 200 3/11/2024
0.8.1 180 3/11/2024
0.8.0 236 2/4/2024
0.8.0-akkad 261 12/8/2023
0.7.4 295 11/20/2023
0.7.3 224 11/17/2023
0.7.2 218 11/16/2023
0.7.2-atlantis 205 11/16/2023
0.7.1 210 11/15/2023
0.7.0-cumae 220 8/26/2023
0.7.0-corcyra 254 8/17/2023
0.7.0-byzantium 221 8/16/2023
0.7.0-bithynia 246 7/26/2023
0.7.0-baalbek 254 7/24/2023
0.7.0-atlantis 533 10/1/2020
0.6.0 1,191 4/12/2020
0.5.4 1,230 8/29/2019
0.5.3 1,287 12/4/2018
0.5.2 1,278 11/30/2018
0.5.1 1,286 11/27/2018
0.5.0 1,360 11/21/2018
0.4.1 1,388 11/2/2018
0.4.0 1,422 10/22/2018