I tried running this example but even after pluggin my application data it would crash on the callback, the reason is that in the startup.cs file the cookie settings are set to require the cookies agreement but the agreement wasn't included in the example page.
The fix is very simple:
Add the file _CookieConsentPartial.cshtml to the shared views folder, containing the following:
@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-page="/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>
}
edit _Layout.cshtml to add the partial view to the following section:
I tried running this example but even after pluggin my application data it would crash on the callback, the reason is that in the startup.cs file the cookie settings are set to require the cookies agreement but the agreement wasn't included in the example page.
The fix is very simple: Add the file _CookieConsentPartial.cshtml to the shared views folder, containing the following:
edit _Layout.cshtml to add the partial view to the following section:
The cookies popup should appear, after agreeing the session storage will work and callback will be able to be completed.