Skip to content

Commit 16fde1e

Browse files
committed
Fixed the refresh issue when we pass layout and updated readme file
1 parent 131bffa commit 16fde1e

File tree

5 files changed

+101
-55
lines changed

5 files changed

+101
-55
lines changed

Controllers/CookieConsentController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public IActionResult CookiePolicy(CookieConsentViewModel model)
7878
string? consent = model.UserConsent?.ToString();
7979
if (!string.IsNullOrEmpty(consent))
8080
ConfirmCookieConsent(consent);
81-
81+
TempData["Layout"] = model.Layout;
8282
return View("CookieConfirmation");
8383
}
8484

README.md

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# UK.NHS.CookieBanner
22

33
# Cookie Banner NuGet Package for .NET Core
4-
This NuGet package provides an easy-to-use cookie banner 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.
4+
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.
55

66
It is designed to work with API calls, SQL server, and custom classes.
77

@@ -12,8 +12,10 @@ You can install the package via NuGet Package Manager or by running the followin
1212
Install-Package UK.NHS.CookieBanner
1313
````
1414

15-
## Usage
15+
# Usage
1616

17+
# Implementing Cookie Banner
18+
## How to Implement Cookie Banner
1719
### Update _Layout.cshtml file
1820

1921
In your _Layout.cshtml file (or any other view where you want to display the cookie banner), add the following code
@@ -31,45 +33,82 @@ Need to add in Header section nhsuk.css if it doesnt exist
3133
@RenderSection("NavBreadcrumbs", false)
3234
```
3335

34-
```bash
35-
<link rel="stylesheet" href="~/_content/UK.NHS.CookieBanner/lib/cookiebanner/css/nhsuk.css" asp-append-version="true" />
36-
```
37-
38-
### Update Program.cs file
39-
Program.cs
36+
#### Cookie banner settings
37+
38+
```bash
39+
"CookieBannerConsent": {
40+
"CookieBannerContent": "",
41+
"ApplicationName": "",
42+
"CookieName": "",
43+
"ExpiryDays": "",
44+
"AnalyticsCookieNamesPrefix": [ "", "" ],
45+
"AnalyticsCookiesDomainName": ""
46+
}
47+
```
4048

49+
# Implementing built-in Cookie Policy page
4150
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.
4251

43-
#### SQL based source
52+
## How to Implement Cookie Policy Page
53+
### SQL based source
54+
#### Add following line in Program.cs
4455
```bash
4556
builder.Services.AddScoped<ICookiePolicyService, CookiePolicyDBService>();
4657
```
58+
#### SQL based source
59+
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:
4760
48-
#### API's
49-
```bash
50-
builder.Services.AddHttpClient<ICookiePolicyApiHttpClient, CookiePolicyApiHttpClient>();
51-
builder.Services.AddScoped<ICookiePolicyService, CookiePolicyAPIService>();
52-
```
53-
54-
55-
#### Get cookie policy content from SQL based source
56-
57-
```bash
61+
- "ConnectionStringName": Specify the name of the connection string from your "ConnectionStrings" section that will be used to connect to your database.
62+
- "CookiePolicySQL": Specify the SQL query that will retrieve the cookie policy information from your database.
63+
- "UpdatedDateSQL": Specify the SQL query that will retrieve the last updated date of the cookie policy from your database.
64+
```bash
5865
"CookiePolicy": {
5966
"ConnectionStringName": "", // Connection name specified in "ConnectionStrings"
6067
"CookiePolicySQL": ""
6168
"UpdatedDateSQL": ""
6269
}
6370
```
64-
or
71+
72+
### API's
73+
#### Add following lines in Program.cs
74+
```bash
75+
builder.Services.AddHttpClient<ICookiePolicyApiHttpClient, CookiePolicyApiHttpClient>();
76+
builder.Services.AddScoped<ICookiePolicyService, CookiePolicyAPIService>();
77+
78+
```
6579
#### Get cookie policy content from API's
66-
```bash
67-
"CookiePolicy": {
80+
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:
81+
82+
83+
- "ApiUrl": Specify the URL of the API that handles the cookie policy requests.
84+
- "CookiePolicyRequestURI": Specify the URI or endpoint on the API that is responsible for managing cookie policy-related requests.
85+
- "ClientIdentityKey": Specify the key or identifier used to authenticate the client making the cookie policy requests.
86+
87+
```bash
88+
"CookiePolicy": {
6889
"ApiUrl": "",
6990
"CookiePolicyRequestURI": ""
7091
"ClientIdentityKey": ""
7192
}
7293
```
94+
95+
# How to use this package in Existing Cookie Policy Page
96+
97+
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.
98+
99+
```bash
100+
@await Html.PartialAsync("_CookiePolicyConfirmation", new CookieConsentViewModel {UserConsent = cookieBannerCookieValue, Layout = Layout})
101+
```
102+
```bash
103+
"CookiePolicy": {
104+
"ControllerName": "",
105+
"ActionName": ""
106+
}
107+
```
108+
109+
- "ControllerName": Specify the name of the controller that will handle the Cookie Policy page logic.
110+
- "ActionName": Specify the name of the action method within the specified controller that will render the Cookie Policy view.
111+
73112
74113
## Contributions
75114
Contributions are welcome! Please feel free to submit issues and pull requests.

Views/CookieConsent/CookieConfirmation.cshtml

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,39 @@
77
ViewData["DoNotDisplayNavBar"] = true;
88
}
99

10-
@section NavBreadcrumbs {
11-
<nav class="nhsuk-breadcrumb" aria-label="Breadcrumb">
12-
<div class="nhsuk-width-container">
13-
<ol class="nhsuk-breadcrumb__list">
14-
<li class="nhsuk-breadcrumb__item">
15-
<a class="nhsuk-breadcrumb__link trigger-loader"
16-
asp-action=@policyActionName
17-
asp-controller=@policyControllerName>Cookie Policy</a>
18-
</li>
19-
<li class="nhsuk-breadcrumb__item">Cookie Consent</li>
20-
</ol>
21-
<p class="nhsuk-breadcrumb__back">
22-
<a class="nhsuk-breadcrumb__backlink">Back to Signposting</a>
23-
</p>
24-
</div>
25-
</nav>
26-
}
27-
<div class="nhsuk-width-container app-width-container">
28-
<div class="nhsuk-grid-row">
29-
<div class="nhsuk-grid-column-full">
30-
<div class="nhsuk-u-reading-width">
31-
<h1>Your cookie settings have been saved</h1>
32-
<p>We'll save your settings for a year.</p>
33-
<p>We'll ask you if you're still OK with us using cookies when either:</p>
34-
<ul>
35-
<li>it's been a year since you last saved your settings</li>
36-
<li>we add any new cookies or change the cookies we use</li>
37-
</ul>
38-
<p>You can also <a href="@Url.Action(policyActionName, policyControllerName)">choose which cookies we use</a> at any time.</p>
39-
</div>
10+
<div>
11+
@section NavBreadcrumbs {
12+
<nav class="nhsuk-breadcrumb" aria-label="Breadcrumb">
13+
<div class="nhsuk-width-container app-width-container">
14+
<ol class="nhsuk-breadcrumb__list">
15+
<li class="nhsuk-breadcrumb__item">
16+
<a class="nhsuk-breadcrumb__link trigger-loader"
17+
asp-action=@policyActionName
18+
asp-controller=@policyControllerName>Cookie Policy</a>
19+
</li>
20+
</ol>
21+
<p class="nhsuk-breadcrumb__back">
22+
<a class="nhsuk-breadcrumb__backlink">Back to Signposting</a>
23+
</p>
24+
</div>
25+
</nav>
26+
}
27+
</div>
28+
<div>
29+
<div class="nhsuk-width-container app-width-container">
30+
<div class="nhsuk-grid-row">
31+
<div class="nhsuk-grid-column-full">
32+
<div class="nhsuk-u-reading-width">
33+
<h1>Your cookie settings have been saved</h1>
34+
<p>We'll save your settings for a year.</p>
35+
<p>We'll ask you if you're still OK with us using cookies when either:</p>
36+
<ul>
37+
<li>it's been a year since you last saved your settings</li>
38+
<li>we add any new cookies or change the cookies we use</li>
39+
</ul>
40+
<p>You can also <a href="@Url.Action(policyActionName, policyControllerName)">choose which cookies we use</a> at any time.</p>
41+
</div>
42+
</div>
4043
</div>
4144
</div>
42-
</div>
45+
</div>

Views/Shared/_CookiePolicyConfirmation.cshtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
@using UK.NHS.CookieBanner.ViewModels
22
@model CookieConsentViewModel;
33
@{
4-
var model = Model;
4+
var model = Model;
55
TempData["Layout"] = (string.IsNullOrEmpty(model.Layout) ? "_Layout" : model.Layout);
6+
model.Layout = TempData["Layout"].ToString();
67

78
if (model == null)
89
{
910
model = new CookieConsentViewModel { UserConsent = "" };
1011
}
1112
}
1213
<form method="post" asp-controller="CookieConsent" asp-action="CookiePolicy">
14+
@Html.HiddenFor(model => model.Layout)
1315
<div class="nhsuk-u-reading-width">
1416
<p>We'll only use these cookies if you say it's OK. We'll use a cookie to save your settings.</p>
1517

Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>@ViewData["Title"] - UK.NHS.CookieBanner</title>
77
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
@*<link href="~/lib/cookiebanner/css/nhsuk.css" rel="stylesheet" />*@
89
<link rel="stylesheet" href="~/_content/UK.NHS.CookieBanner/lib/cookiebanner/css/nhsuk.css" asp-append-version="true" />
910
</head>
1011
<body>
1112

1213
@RenderSection("NavBreadcrumbs", false)
14+
@*<partial name="_CookieConsentPartial" />*@
1315
<div class="container">
1416
<main role="main" class="pb-3">
1517
@RenderBody()

0 commit comments

Comments
 (0)