title: How to set consent cookie in Blazor Server
body: <p>I have a Blazor 3.1 App with Identity where I want to implement a cookie consent banner.</p>
  
  <p>In classic ASP .NET Core, there is a nice template for a cookie consent banner. </p>
  
  <pre class="lang-cs prettyprint-override"><code>    @using Microsoft.AspNetCore.Http.Features
  
      @{
          var consentFeature = Context.Features.Get&lt;ITrackingConsentFeature&gt;();
          var showBanner = !consentFeature?.CanTrack ?? false;
          var cookieString = consentFeature?.CreateConsentCookie();
      }
  
      @if (showBanner)
      {
          &lt;div class="container"&gt;
              &lt;div id="cookieConsent" class="alert alert-info alert-dismissible fade show" role="alert"&gt;
                  Use this space to summarize your privacy and cookie use policy. &lt;a class="alert-link" asp-area="" asp-controller="Home" asp-action="Privacy"&gt;Learn More&lt;/a&gt;.
                  &lt;button type="button" class="accept-policy close" data-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString"&gt;
                      &lt;span aria-hidden="true"&gt;Accept&lt;/span&gt;
                  &lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;script&gt;
              (function () {
                  var button = document.querySelector("#cookieConsent button[data-cookie-string]");
                  button.addEventListener("click", function (event) {
                      document.cookie = button.dataset.cookieString;
                  }, false);
              })();
          &lt;/script&gt;
      }
  </code></pre>
  
  <p>If you are placing this partial in the layout, you have a perfect working cookie consent banner. If configured appropriately, users cant even login to the Identity Framework until they consent.</p>
  
  <p>Because Blazor does not know a HttpContext, this template is not working. Is there a boilerplate way or do I have to create this feature this by myself?</p>