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