Hello All,
Recently i have faced one interview question that Which is more secure from ViewData, ViewBag, and TeampData ?
Can someone help me to answer this question ?
Thanks in advance.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ramesh PalanivelRank #372 · 6.8K reputationPosted Aug 21, 2017, 1:36 AM EDT
Rupesh KahaneRank #136 · 16.4K reputationPosted Aug 21, 2017, 1:49 AM EDT
Puneet KankarRank #446 · 5.6K reputationPosted Aug 21, 2017, 4:36 AM EDT
TempData persists only until the next page access; ViewBag is used to pass values from the controller to the view. Neither are suitable for storing information which will last for the session. On security, they are both server side and the user will not be aware of them, so, yes, they are secure.
If you want to persists values for the duration of a session they you need a different mechanism. Several are available to you. My favourite is the use of session variables but some developers are firmly against session variables. You need to research your options further.