I've blogged before about making your MVC controllers sessionless.  The knock on sessionless controllers is that TempData is off the table because it uses Session as its data store.

If you see the TempData name and dismiss it, thinking it's another dictionary like Session[] and ViewData[] and you're waaaay past that since your mister type-safe, take another look.  The neat thing about TempData is that it lasts for one more page load and then "poof" - it's gone.  It self destructs as soon as it has been read.

Sure, it's a dictionary with magic string keys, but it's a great place to store message like "Your changes were saved" when you redirect to another page.

So how do we get the benefits of TempData as an ephemeral application message store, but go all-in on the web farm with sessionless controllers?


I can hear you groaning.  Cookies are old school!  They can't hold much information!  They aren't secure!

Fine, don't put much in there, and don't put your secret fried chicken recipe in there.  We're just going to use this as a little string to tell the user everything is OK or it's not OK.

TempData uses a provider model for the data store, and Session is the default data store.  But you can get a cookie data store, CookieTempDataProvider, with Mvc3Futures NuGet package:


This should work as a TempData provider, but now it has to be wired into the application.  Here's how you can do that:

public class BaseController : Controller
    protected override ITempDataProvider CreateTempDataProvider()
        return new CookieTempDataProvider(HttpContext);