0

I've got a simple controller action that sets a Session variable called "firm" to my validated model.

[HttpPost]
    public ActionResult ClientProfile(ClientProfileFormModel model)
    {
        if (ModelState.IsValid)
        {
            System.Web.HttpContext.Current.Session["firm"] = model;
            return View("ClientProfileConfirmation",model);
        }

        return View(model);
    }

After the user clicks a link to confirm, the link sends them to this action:

public ActionResult ClientProfileConfirmationSubmit()
    {

        var model = (ClientProfileFormModel)System.Web.HttpContext.Current.Session["firm"];

        string emailToAdminBody = GenerateFirmProfileAdminEmail(model);
        EmailLogic.Instance.SendEmail("test@test.com", "test@test.com", "Firm profile from " + model.FirmAddress.Name, emailToAdminBody);

        return View(model);
    }

My issue is: model is null. Through the debugger, I can confirm that the "firm" session variable is set. But when the second action is entered, the session variable is no longer there, and model gets set to null. I'm stumped as to what this could be. I've scoured Stackoverflow for solutions.

I've tried both System.Web.HttpContext.Current.Session[] and just Session[].

I've tried adding the SessionStateModule like this answer suggests: HttpContext.Current.Session is null when routing requests

I've tried manually starting the ASP State Service on my local machine.

I've even tried changing the model to a simple string, and trying to retrieve that, with no luck, so it can't be the model causing an issue.

Community
  • 1
  • 1
adam3039
  • 1,171
  • 14
  • 27

1 Answers1

0

Turns out I didn't have sessions enabled in my web.config.

<configuration>
  ...
<system.web>
  <pages enableSessionState="true">
    <controls>
    ...
    </controls>
  </pages>
  ...
  <sessionState cookieless="AutoDetect" mode="StateServer" timeout="22" />
</system.web>
  ...
</configuration>
adam3039
  • 1,171
  • 14
  • 27