title: ASP.NET Core 3.1 _CookieConsentPartial.cshtml accept cookie
body: <p>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.</p>
  <p>After publishing the website to IIS, the cookie is not being set so flipping between pages I get the cookie warning.</p>
  <p>The partial cshtml file and startup.cs are untouched so at a loss as to why the cookie is not being set:</p>
  <pre><code>@{
      var consentFeature = Context.Features.Get&lt;ITrackingConsentFeature&gt;();
      var showBanner = !consentFeature?.CanTrack ?? false;
      var cookieString = consentFeature?.CreateConsentCookie();
  }
  
  @if (showBanner)
  {
  
  ....(div and cookie text omitted for brevity)
  
  
  &lt;script&gt;
      (function () {
          var button = document.querySelector(&quot;#cookieConsent button[data-cookie-string]&quot;);
          button.addEventListener(&quot;click&quot;, function (event) {
              document.cookie = button.dataset.cookieString;
          }, false);
      })();
  </code></pre>
  <p>Thanks</p>