Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does TempData store its data?

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?

like image 468
AngryHacker Avatar asked May 18 '26 13:05

AngryHacker


1 Answers

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.

like image 119
Ashish Mishra Avatar answered May 20 '26 05:05

Ashish Mishra