Reputation: 61596
There is a similar question from years ago regarding the old ASP.NET. I was wondering whether it's different for .NET Core.
In the linked question, it states that TempData is stored in Session, which by default is tied to a single server. So to make it work on server farm, I'd have to utilize a State Server of some type.
Has this behavior changed with .NET Core to better support web farms?
Upvotes: 3
Views: 5623
Reputation: 687
TempData is implemented by TempData providers using either cookies or session state. By default cookies are used to store the data. But you can choose to use session based TempData providers.
1) If your system already using session then Session based TempData provider is easy to use.
2)If your app run in a server farm on multiple servers? , there's no additional configuration required to use the cookie TempData provider outside of Data Protection.
3)If small amount of data is going to be stored in tempdata then cookie is best option.
Cookie name:
AspNetCore.Mvc.CookieTempDataProvider
You can confgiure the name of cookie as below:-
services.Configure<CookieTempDataProviderOptions>(options => options.Cookie.Name = "MyTempDataCookie");
You can also write your implementation of ITempDataProvider and register that instead of default one.
Upvotes: 5
Reputation: 514
In ASP.NET Core 2.0 or later, the cookie-based TempData provider is used by default to store TempData in cookies.
Source: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-2.2#tempdata
Upvotes: 2