TempData: Is It Safe?

ek_ny picture ek_ny · Nov 23, 2011 · Viewed 9k times · Source

I am using the TempData in order to preserve my model in when using a RedirectToAction. It works fine, but I have a nagging feeling that it might not be the right thing to do. I really try to avoid using Session data, and I've read that TempData uses the Session. Is it safe to use? Are there issues which might arise in using it in a load balanced environment?

Trivia Question: "Is It Safe?"-- name the movie.

Answer

Rich O'Kelly picture Rich O'Kelly · Nov 23, 2011

Yes, TempData is backed by session storage, so if you are in a load balanced environment extra care must be taken when using it (sticky sessions, persistent session state, etc).

TempData has been the de-facto choice when using the PRG pattern, and is what it was designed for.

As to whether it's the right thing to do... it depends on your use case!

PS Marathon Man.