fix(cookie): Fehlerhaften Consent-Cookie-Button entfernt und durch von Microsoft empfohlene Struktur ersetzt
- Den fehlerhaften Consent-Cookie-Button entfernt und die von Microsoft empfohlene Struktur integriert, um die Compliance und Funktionalität zu verbessern.
This commit is contained in:
@@ -1,27 +1,26 @@
|
||||
@{
|
||||
var nonce = _accessor.HttpContext?.Items["csp-nonce"] as string;
|
||||
}
|
||||
@using DigitalData.Core.DTO;
|
||||
@using Microsoft.AspNetCore.Http.Features
|
||||
@using Newtonsoft.Json.Serialization;
|
||||
@using Newtonsoft.Json;
|
||||
@inject CookieConsentSettings _cookieSettings
|
||||
@using Microsoft.AspNetCore.Http.Features
|
||||
|
||||
@{
|
||||
var nonce = _accessor.HttpContext?.Items["csp-nonce"] as string;
|
||||
var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
|
||||
var showBanner = !consentFeature?.CanTrack ?? false;
|
||||
var cookieString = consentFeature?.CreateConsentCookie();
|
||||
}
|
||||
|
||||
@if (showBanner)
|
||||
{
|
||||
<script nonce="@nonce">
|
||||
@{
|
||||
var serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
string serializedProps = JsonConvert.SerializeObject(_cookieSettings, serializerSettings);
|
||||
}
|
||||
var props = @Html.Raw(serializedProps);
|
||||
var cookieSettings = new BootstrapCookieConsentSettings(props)
|
||||
</script>
|
||||
<div id="cookieConsent" class="alert alert-info alert-dismissible fade show" role="alert">
|
||||
Use this space to summarize your privacy and cookie use policy. <a asp-page="/Privacy">Learn More</a>.
|
||||
<button type="button" class="accept-policy close" data-bs-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">
|
||||
<span aria-hidden="true">Accept</span>
|
||||
</button>
|
||||
</div>
|
||||
<script nonce="@nonce">
|
||||
(function () {
|
||||
var button = document.querySelector("#cookieConsent button[data-cookie-string]");
|
||||
button.addEventListener("click", function (event) {
|
||||
document.cookie = button.dataset.cookieString;
|
||||
}, false);
|
||||
})();
|
||||
</script>
|
||||
}
|
||||
Reference in New Issue
Block a user