Prerequisites for Episerver Integration
In order to be able to use the Episerver Integration, you'll need to have a few things set up first:
- An account with Cookie Information. If you haven't created one yet, please visit app.cookieinformation.com and sign up.
- Your domain must be added in the Cookie Information Platform.
- A Visual Studio project with Episerver set up, and running. If you have yet to do this, please refer to the Episerver documentation for setting up a project.
Features of the Episerver Integration
Complying with user consents can be somewhat tricky on Episerver based sites due to cookies being set in multiple places. For this reason, the following features are part of the integration:
Cookie Consent Pop-up registration: makes sure that the Cookie Information consent pop-up is shown on all necessary pages in the correct language.
IVistorConsentService (Implemented in VistorConsentService): you can query this service to find out whether the current visitor has given consent to a specific cookie category or cookie.
ICookieMappingService (Implemented in CookieMappingService): Maps cookies to the correct categories for the IVisitorConsentService. You can access it via an IInitializeModule if you would like to add cookie definitions - by default, definitions will be loaded from configuration.
HtmlHelper.CreateConditionalCookieScript: is an extension method that can be found in the CookieInformation.Episerver.Helpers namespace. It can wrap a section of razor code and automatically load the snippet as soon as consent to cookies has been given by the user.
CookieConsentCriterion: is a visitor group criteria that allows editors to personalise content based on the user consents given.
HTTPModule: is a module that can clean server side cookies that have been set (with no consent given) before returning a response. It can also remove cookies where consent has been withdrawn for them if a user updates their settings.
Episerver UI Integration: provides a shortcut to the Cookie Information dashboard from within the Episerver edit mode.
Installing the Episerver Integration
Install-Package CookieInformation.Episerver -Version 1.0.16
Alternatively, there are also commands available for other Package Managers:
dotnet add package CookieInformation.Episerver --version 1.0.16
<PackageReference Include="CookieInformation.Episerver" Version="1.0.16" />
paket add CookieInformation.Episerver --version 1.0.16
Configuring the Episerver Integration
The integration can be configured via the AppSettings (normally found in web.config).
The first thing you'll be presented with are the Cookie Category mappings like so:
Each key should have a comma (",") separating cookie names. Instead of a cookie name, you can also use Regular Expressions - but the expression must start with "¨^" and end with "$".
In addition to the normal configuration, there are some other settings you can tailor to your own liking:
REGISTER-CONSENT-SCRIPT defaults to true. If you'd like to manually insert the pop-up script manually, then set it to false.
EMBED-DASHBOARD defaults to false. This means that in Episerver edit mode, the menu integration with only link to the Cookie Information dashboard. If it is set to true, then it will be embedded in an iFrame.
FALLBACKCONSENT has a default value of false. If a cookie or category isn't known, then this indicates the default consent (in this case, that consent has not been given as is legally required).
REMOVEOLD defaults to false. If it is set to true then cookies in a visitors browser that they have not given consent to will expire.
FILTER:DISABLE defaults to false. If it is set to true, then the HTTPModule that automatically removes server side cookies from the response is disabled.
It can be useful to set the value to true for troubleshooting purposes as long as all server side cookies are already taken care of manually.
ALLOW-FOR-ROLES has a default value of "Authenticated" and includes a comma separated list of roles where all cookies should be allowed. The authentication check is disabled.
Allowing a script to fire immediately upon user acceptance of cookies
// Script that will set a marketing cookie
console.log('There is consent to Marketing cookies');
If consent has already been given, then the function will run. If it hasn't, an eventhandler will register and the function will run as soon as the user has consented.
Setting custom cookies in server side code
In some cases, you might need to set custom cookies in your server side code. You can either access the VisitorConsentService via the static "Current" property, or instead use Episerver's depenency injection (like in the example below):
public class CookieInit : IInitializableModule
public void Initialize(InitializationEngine context)
var cookieMapper = ServiceLocator.Current.GetInstance<ICookieMappingService>();
public void Uninitialize(InitializationEngine context)
- A Cookie Information account with a domain added in the platform
- An up and running Episerver project
- Integration installed via NuGet or your package manager of choice
- Cookies mapped to categories
- Any further configuration changes you have made