title: Using Antiforgery in ASP.NET Core and got error - the antiforgery token could not be decrypted
body: <p>My ASP.Net Core MVC application have added <strong>Antiforgery</strong> middleware like below:</p>
  <p><strong>startup.cs</strong></p>
  <pre><code>services.AddMvc();
  services.AddSession();
  services.AddCaching();
  services.AddSession(o =&gt;
  {
    o.IdleTimeout = TimeSpan.FromMinutes(120);
  });
  services.AddAntiforgery();
  </code></pre>
  <p>I've added below in the view and controller</p>
  <p><strong>View:</strong></p>
  <pre><code>&lt;form action=&quot;/Home/Login&quot; method=&quot;post&quot; id=&quot;staff-login&quot; autocomplete=&quot;off&quot;&gt;
      @Html.AntiForgeryToken()
   ...
  </code></pre>
  <p><strong>Controller</strong></p>
  <pre><code>[HttpPost, ValidateAntiForgeryToken] 
  public IActionResult Login(IFormCollection formCollection) 
  {...}
  </code></pre>
  <p>The problem is users always get below when users come across different forms.</p>
  <blockquote>
  <p>System.InvalidOperationException: The antiforgery token could not be
  decrypted. ---&gt; System.Security.Cryptography.CryptographicException:
  The key {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} was not found in the
  key ring.</p>
  </blockquote>
  <p>I found a solution which suggests setting a static pair of validation/decryption key in the web.config but it seems this solution is only for classic asp.net application. How should I do in ASP.Net core?</p>