In Controller, I save a collection of errors into cookies
via TempData
var messages = new List<Message>();
...
TempData.Put("Errors", messages);
TempData.Put is an extension method
public static class TempDataExtensions
{
public static void Put<T>(this ITempDataDictionary tempData, string key, T value) where T : class
{
tempData[key] = JsonConvert.SerializeObject(value);
}
public static T Get<T>(this ITempDataDictionary tempData, string key) where T : class
{
tempData.TryGetValue(key, out object o);
return o == null ? null : JsonConvert.DeserializeObject<T>((string)o);
}
}
When HTML is loaded, I see
and several cookies were created (Chrome Developer Tools > Application > Storage > Cookies)
The issue I think, is that total size of Cookies is hitting some Cookie Size limit somewhere.
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 TempData
?
I tried the second approach and if I change the startup.cs file
\\ ConfigureServices method
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddSessionStateTempDataProvider();
services.AddSession();
\\ Configure method
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
The TempData are still using Cookies, do I forgot some setting somewhere ?