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:
parent
fc171e5b89
commit
5c4acd17a0
@ -63,6 +63,15 @@ try
|
|||||||
q.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
|
q.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.Services.Configure<CookiePolicyOptions>(options =>
|
||||||
|
{
|
||||||
|
// This lambda determines whether user consent for non-essential
|
||||||
|
// cookies is needed for a given request.
|
||||||
|
options.CheckConsentNeeded = context => true;
|
||||||
|
|
||||||
|
options.MinimumSameSitePolicy = SameSiteMode.None;
|
||||||
|
});
|
||||||
|
|
||||||
if (config.GetValue<bool>("EnableSwagger") && builder.IsDevOrDiP())
|
if (config.GetValue<bool>("EnableSwagger") && builder.IsDevOrDiP())
|
||||||
{
|
{
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
@ -187,7 +196,7 @@ try
|
|||||||
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
//app.UseCookiePolicy();
|
app.UseCookiePolicy();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
|||||||
@ -1,27 +1,26 @@
|
|||||||
@{
|
@using Microsoft.AspNetCore.Http.Features
|
||||||
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
|
|
||||||
@{
|
@{
|
||||||
|
var nonce = _accessor.HttpContext?.Items["csp-nonce"] as string;
|
||||||
var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
|
var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
|
||||||
var showBanner = !consentFeature?.CanTrack ?? false;
|
var showBanner = !consentFeature?.CanTrack ?? false;
|
||||||
var cookieString = consentFeature?.CreateConsentCookie();
|
var cookieString = consentFeature?.CreateConsentCookie();
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (showBanner)
|
@if (showBanner)
|
||||||
{
|
{
|
||||||
<script nonce="@nonce">
|
<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>.
|
||||||
var serializerSettings = new JsonSerializerSettings
|
<button type="button" class="accept-policy close" data-bs-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">
|
||||||
{
|
<span aria-hidden="true">Accept</span>
|
||||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
</button>
|
||||||
};
|
</div>
|
||||||
string serializedProps = JsonConvert.SerializeObject(_cookieSettings, serializerSettings);
|
<script nonce="@nonce">
|
||||||
}
|
(function () {
|
||||||
var props = @Html.Raw(serializedProps);
|
var button = document.querySelector("#cookieConsent button[data-cookie-string]");
|
||||||
var cookieSettings = new BootstrapCookieConsentSettings(props)
|
button.addEventListener("click", function (event) {
|
||||||
</script>
|
document.cookie = button.dataset.cookieString;
|
||||||
|
}, false);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user