C# – Session Flash vs TempData in ASP.NET MVC 3

asp.net-mvc-3c

A little background. A developer I used to work with insisted on disabling Tempdata and using Session Flash for passing data in the return view.

Question is, is there any advantage to doing it this way? using a flash message is great for returning data to the user but I've had headaches with passing data from one post to the next with tempdata disabled.

Is there any problem with using flash and tempdata together or is this a major coding faux paus?

Best Answer

Temporarily putting things in the session is going to lead to strange behavior when a user opens up 2 or more windows. TempData is best for persisting data briefly.

Also, sessions can be cleared a variety of ways. TempData will rewrite a bit of data on the page to be posted back and will last as long as the window isn't closed.

There's also the problem of session scalability. Most applications won't run into a problem here but larger applications can be affected.

If you're still not convinced here's a coding guidelines document from Microsoft encouraging the use of tempdata over the session