1. Added _CookieConseentPartial.cshtml Partial View
2. Used _CookieConseentPartial partial view in _Layout View 3. Added Privacy View Controller and View
This commit is contained in:
parent
0296735cb9
commit
8110a95111
16
src/Web/WebMVC/Controllers/HomeController.cs
Normal file
16
src/Web/WebMVC/Controllers/HomeController.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace WebMVC.Controllers
|
||||||
|
{
|
||||||
|
public class HomeController : Controller
|
||||||
|
{
|
||||||
|
public IActionResult Privacy()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
6
src/Web/WebMVC/Views/Home/Privacy.cshtml
Normal file
6
src/Web/WebMVC/Views/Home/Privacy.cshtml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Privacy Policy";
|
||||||
|
}
|
||||||
|
<h2>@ViewData["Title"]</h2>
|
||||||
|
|
||||||
|
<p>Use this page to detail your site's privacy policy.</p>
|
41
src/Web/WebMVC/Views/Shared/_CookieConsentPartial.cshtml
Normal file
41
src/Web/WebMVC/Views/Shared/_CookieConsentPartial.cshtml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
@using Microsoft.AspNetCore.Http.Features
|
||||||
|
|
||||||
|
@{
|
||||||
|
var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
|
||||||
|
var showBanner = !consentFeature?.CanTrack ?? false;
|
||||||
|
var cookieString = consentFeature?.CreateConsentCookie();
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (showBanner)
|
||||||
|
{
|
||||||
|
<nav id="cookieConsent" class="navbar navbar-default navbar-fixed-top" role="alert">
|
||||||
|
<div class="container">
|
||||||
|
<div class="navbar-header">
|
||||||
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#cookieConsent .navbar-collapse">
|
||||||
|
<span class="sr-only">Toggle cookie consent banner</span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
</button>
|
||||||
|
<span class="navbar-brand"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span></span>
|
||||||
|
</div>
|
||||||
|
<div class="collapse navbar-collapse">
|
||||||
|
<p class="navbar-text">
|
||||||
|
Use this space to summarize your privacy and cookie use policy.
|
||||||
|
</p>
|
||||||
|
<div class="navbar-right">
|
||||||
|
<a asp-controller="Home" asp-action="Privacy" class="btn btn-info navbar-btn">Learn More</a>
|
||||||
|
<button type="button" class="btn btn-default navbar-btn" data-cookie-string="@cookieString">Accept</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
document.querySelector("#cookieConsent button[data-cookie-string]").addEventListener("click", function (el) {
|
||||||
|
document.cookie = el.target.dataset.cookieString;
|
||||||
|
document.querySelector("#cookieConsent").classList.add("hidden");
|
||||||
|
}, false);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
}
|
@ -49,6 +49,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
<partial name="_CookieConsentPartial" />
|
||||||
|
|
||||||
@RenderBody()
|
@RenderBody()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user