Really struggling with an MVC / TempData / Session / possibly IIS6 type issue.
I've got a simple MVC website - primary controller looks like this:
public class DemoController : Controller
{
[HttpPost]
public RedirectToRouteResult Index(SomeObject obj)
{
_someService.DoStuffWith(obj);
TempData.Add("SomeObject", obj);
return RedirectToAction("Index");
}
[HttpGet]
public ViewResult Index()
{
var obj = TempData.Peek("SomeObject") as SomeObject;
return View("Hello", obj);
}
}
So this is a mega-simple Post Redirect Get - submit data from somewhere, get it in the Post-friendly action, do stuff with it, poke it into temp data, redirect to Get-friendly, pick it up again, stick the user on a new view with the object in the model. Have implemented this a dozen times before, and never had a problem, but it's always been on IIS7.
This works exactly as expected when running locally, both on cassini, and on local IIS 7.5. However, as soon as I deploy to Server 2003 and IIS6, the first time I try to access any property of the "SomeObject" model in the view, I get a null reference exception.
So, what else have I tried:
- I've ditched TempData and just pushed it into Session["Whatever"] - with same results
- I've pushed into HttpContext.Current.Session["Whatever"] - with same results
- I've pushed into ControllerContext.HttpContext.Session["Whatever"] - with same results
(Admittedly, i'm sketchy on the differences between these - have never needed to worry about it before now)
- I've made sure session state is switched on on IIS.
- I've checked that the Asp.net session identifier is not changing between requests.
- I've deployed to 2 separate servers, both running 2003 and IIS6, same results on both
- Explicitely used SessionStateBehaviour.Required
What i'm not able to do:
- Deploy to IIS7, outside my local machine
- Use SqlServer SessionState
- Use StateServer SessionState
Also worth mentioning that this site is using the MVC4 RC - though the RC features are not used in this particular section of the site.
Any ideas or comments are most welcome!
Thanks.