This NuGet package provides an easy-to-use cookie banner and cookie policy page for .NET Core web applications. The cookie banner allows you to comply with the EU Law and the GDPR by informing users about the use of cookies on your website and giving them the option to accept or decline cookies.
It is designed to work with API calls, SQL server, and custom classes.
You can install the package via NuGet Package Manager or by running the following command in the Package Manager Console:
Install-Package UK.NHS.CookieBannerIn your _Layout.cshtml file (or any other view where you want to display the cookie banner), add the following code Need to add in Header section nhsuk.css if it doesnt exist
<link rel="stylesheet" href="~/_content/UK.NHS.CookieBanner/lib/cookiebanner/css/nhsuk.css" asp-append-version="true" /><partial name="_CookieConsentPartial" /> @RenderSection("NavBreadcrumbs", false) "CookieBannerConsent": {
  "CookieBannerContent": "",
  "ApplicationName": "",
  "CookieName": "",
  "ExpiryDays": "",
  "AnalyticsCookieNamesPrefix": [ "", "" ],
  "AnalyticsCookiesDomainName": ""
}There is a possibility of utilising various sources to populate the cookie policy content through different means, including calling APIs, using a SQL server, or implementing a custom approach.
builder.Services.AddScoped<ICookiePolicyService, CookiePolicyDBService>();To configure the "CookiePolicy" section in your appsettings file, you need to provide the appropriate values for each property. Here's an explanation of each property:
- "ConnectionStringName": Specify the name of the connection string from your "ConnectionStrings" section that will be used to connect to your database.
- "CookiePolicySQL": Specify the SQL query that will retrieve the cookie policy information from your database.
- "UpdatedDateSQL": Specify the SQL query that will retrieve the last updated date of the cookie policy from your database.
 "CookiePolicy": {
   "ConnectionStringName": "", // Connection name specified in "ConnectionStrings"
   "CookiePolicySQL": ""
   "UpdatedDateSQL": ""
 }builder.Services.AddHttpClient<ICookiePolicyApiHttpClient, CookiePolicyApiHttpClient>();
builder.Services.AddScoped<ICookiePolicyService, CookiePolicyAPIService>();
To configure the "CookiePolicy" section in your appsettings file, you need to provide the appropriate values for each property. Here's an explanation of each property:
- "ApiUrl": Specify the URL of the API that handles the cookie policy requests.
- "CookiePolicyRequestURI": Specify the URI or endpoint on the API that is responsible for managing cookie policy-related requests.
- "ClientIdentityKey": Specify the key or identifier used to authenticate the client making the cookie policy requests.
  "CookiePolicy": {   
    "ApiUrl": "",
    "CookiePolicyRequestURI": ""
    "ClientIdentityKey": ""
  }If you wish to use your own policy page, please update the "ControllerName" and "ActionName" in the appsettings file. When using your own cookie policy, ensure that you utilise the existing cookie consent confirmation partial view. This view is responsible for updating analytical cookies and the user consent cookie.
@await Html.PartialAsync("_CookiePolicyConfirmation", new CookieConsentViewModel {UserConsent = cookieBannerCookieValue, Layout = Layout})"CookiePolicy": {
   "ControllerName": "", 
   "ActionName": ""
 }- "ControllerName": Specify the name of the controller that will handle the Cookie Policy page logic.
- "ActionName": Specify the name of the action method within the specified controller that will render the Cookie Policy view.
Contributions are welcome! Please feel free to submit issues and pull requests.
This project is licensed under the MIT License. See the LICENSE file for details.