0

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.

3
  • Welcome to the Session hell :-) Since I have stopped using Sessions in my applications I feel I am in the paradise. Commented Jul 26, 2012 at 12:10
  • Have you tried just using the indexer on temp data? e.g. Commented Jul 26, 2012 at 13:35
  • Yeah - have tried all available permutations of putting stuff into and taking stuff out of tempdata - all with the exact same results... Commented Jul 26, 2012 at 16:14

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.