0
votes

The out of the box MVC partial (_CookieConsentPartial.cshtml) for setting an acceptance cookie in ASP.NET Core 3.1 web application works fine when running the site in Visual Studio 2019, i.e. I see the cookie being set and then no longer see the cookie message div container subsequently.

After publishing the website to IIS, the cookie is not being set so flipping between pages I get the cookie warning.

The partial cshtml file and startup.cs are untouched so at a loss as to why the cookie is not being set:

@{
    var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
    var showBanner = !consentFeature?.CanTrack ?? false;
    var cookieString = consentFeature?.CreateConsentCookie();
}

@if (showBanner)
{

....(div and cookie text omitted for brevity)


<script>
    (function () {
        var button = document.querySelector("#cookieConsent button[data-cookie-string]");
        button.addEventListener("click", function (event) {
            document.cookie = button.dataset.cookieString;
        }, false);
    })();

Thanks

1

1 Answers

0
votes

Quick update on my progress with this one to share the solution in the event anyone else gets tripped up by this

The website when published to IIS must have a SSL binding/being forced onto https:// whilst using the site.

I installed a cert & setup redirect rule and hey presto.... the Consent Cookie get's created! Hooray!

Cheers,

Rob