tags:

views:

150

answers:

2

I'm using SQL state server for session variables. I'm also storing ViewData in TempData so I can access the ModelState across a redirect. The problem is that the ViewDataDictionary is not serializable. Is there a way to hook into the session storage logic to serialize the ViewDataDictionary when the Session variable is stored?

Thanks.

A: 

I think you're breaking a fundamental idea of the MVC pattern.

You shouldn't need the session variable. You pass the model to the view, then the model is passed back to the controller. It doesn't matter if it's a redirect or not.

IainMH
While I do agree that MVC aims to eliminate the need for a Session, some use cases will still require it. For instance, I need to hold some user information while the user is redirected to a third party to complete a process. Once the process is complete, the 3rd party will callback and my application needs to validate the request against existing user session data.
nick
Most 3rd party web based APIs (such as PayPal) allow you to specify a callback URL which they invoke when their operation is complete. If this is the case, you can specify a key to your model state in the callback url, which you then look up in the controller. (remember to make the key a one-time secure key if you want to avoid spoofing attack)
DSO
A: 

Instead of storing the whole ViewData dictionary in TempData, I just stored the values I needed. A bit hacky, but it'll work for now.

nick