ASP.NET CreateConsentCookie (_CookieConsentPartial.cshtml) Not Working in IE and Edge

Viewed 456

I'm using ASP.NET 3.1, using the CookiePolicy feature

// Startup
services.Configure<CookiePolicyOptions>(options =>
{
    options.CheckConsentNeeded = context => true;
    options.MinimumSameSitePolicy = SameSiteMode.None;
});

// Configure
app.UseCookiePolicy();

That's the default _CookieConsentPartial.cshtml offered by Microsoft

@using Microsoft.AspNetCore.Http.Features

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

@if (showBanner)
{
    <div id="cookieConsent" class="alert alert-info alert-dismissable show" style="font-weight:bold" role="alert">
        We use cookies to improve your browing experience. Please review our <a asp-page="/privacy">Cookie Policy</a> and click accept to continue.
        <button type="button" class="accept-policy close" data-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">
            <span aria-hidden="true">Accept</span>
        </button>
    </div>
    <script>
        (function () {
            var button = document.querySelector("#cookieConsent button[data-cookie-string]");
            button.addEventListener("click", function (event) {
                document.cookie = button.dataset.cookieString;
                document.getElementById("cookieConsent").style.visibility = "hidden";
            }, false);
        })();
    </script>
}

It's working fine in Chrome and FireFox, but the cookie isn't set in IE and Edge. I'm surprised I'm not seeing any other people complaining about this issue online!

The only thing I could find is this:

After searching a lot for exact answer, I found that Internet Explorer (all versions) doesn't allow you to specify a domain of localhost, a local IP address or machine name. When you do, Internet Explorer simply ignores the cookie.

However, I'm not setting the cookie domain. Does Microsoft's CreateConsentCookie support its own browser?

0 Answers
Related