Reputation: 2469
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:
(Admittedly, i'm sketchy on the differences between these - have never needed to worry about it before now)
What i'm not able to do:
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.
Upvotes: 0
Views: 2130
Reputation: 14331
The problem for me was I had this set in my web.config file, but wasn't using SSL:
<httpCookies requireSSL="true" />
This setting prevents cookies from working over unsecure (i.e. non-SSL) connections - including the ASP.NET session cookie.
Upvotes: 0
Reputation: 11
This was the problem on my system - I had a server name that contained underscores. Underscores are not allowed in host names by RFC 952 and may interfere with the ability to set cookies and thus to persist sessions.
To track this down I started watching the SessionID in each controller section and noticed that with every post it was changing. This was only happening on our test server because we named it with _t to show it was a test machine. OUCH!
I found this point.
That may offer other value.
I hope this helps
David
Upvotes: 1