title: TempData Cookie Issue. The size of the request headers is too long
body: <p>In <strong>Controller</strong>, I save a collection of errors into <code>cookies</code> via <code>TempData</code></p>
  
  <pre><code>var messages = new List&lt;Message&gt;();
  ...
  TempData.Put("Errors", messages);
  </code></pre>
  
  <p>TempData.Put is an extension method</p>
  
  <pre><code>public static class TempDataExtensions
      {
  
          public static void Put&lt;T&gt;(this ITempDataDictionary tempData, string key, T value) where T : class
          {
              tempData[key] = JsonConvert.SerializeObject(value);
          }
  
          public static T Get&lt;T&gt;(this ITempDataDictionary tempData, string key) where T : class
          {
              tempData.TryGetValue(key, out object o);
              return o == null ? null : JsonConvert.DeserializeObject&lt;T&gt;((string)o);
          }
      }
  </code></pre>
  
  <p>When HTML is loaded, I see</p>
  
  <p><a href="https://i.stack.imgur.com/3WGdW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3WGdW.png" alt="enter image description here"></a></p>
  
  <p>and several cookies were created (Chrome Developer Tools > Application > Storage > Cookies)</p>
  
  <p><a href="https://i.stack.imgur.com/vRKze.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vRKze.png" alt="enter image description here"></a></p>
  
  <p>The issue I think, is that total size of Cookies is hitting some Cookie Size limit somewhere.</p>
  
  <p>So I have two questions :
  Is it possible to change the cookie size limit (in web.config for example) ?
  Is it possible to use session instead of cookies for <code>TempData</code> ?</p>
  
  <p>I tried the second approach and if I change the <strong>startup.cs</strong> file</p>
  
  <pre><code>\\ ConfigureServices method
  
  services.AddMvc()
     .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
     .AddSessionStateTempDataProvider();
  
  services.AddSession();
  
  \\ Configure method
  
  app.UseSession();
  
  app.UseMvc(routes =&gt;
  {
       routes.MapRoute(
       name: "default",
       template: "{controller=Home}/{action=Index}/{id?}");
  });
  </code></pre>
  
  <p>The TempData are still using Cookies, do I forgot some setting somewhere ?</p>