3

I have an issue with sessions in an MVC3 application. In one controller I am receiving a post request then adding the value to session before redirecting to the controllers get method.

The issue is that in the GET request the session value returns null even though in the POST request the sessions value was set.

[HttpPost]
public ActionResult findPerson(PersonSearch searchDetails)
{
    Session["FindPersons"] = searchDetails;
    return RedirectToAction("findperson");
}


[HttpGet]
public ActionResult findperson()
{
    PersonSearch searchDetails = (PersonSearch)Session["FindPersons"];
Matt Seymour
  • 8,880
  • 7
  • 60
  • 101

2 Answers2

5

Solution:

Some nutter named the session state cookie name in the web.config and the authentication forms name the same thing.

<sessionState timeout="20" cookieName="Spacer" />

<forms loginUrl="/spacer/login" name="Spacer" timeout="2200" />

Obviously the effect it was having was trying to store session and cookies in something called the same thing. Im very surprised this just did not blow up.

Thanks for your help @dknaack, I wouldnt have spotted this so quickly if you were not pointing me in the correct direction.

Matt Seymour
  • 8,880
  • 7
  • 60
  • 101
1

I tryed your code and don't run in this problem. So i looked at the ASP.NET Forum.

There is a post RedirectToAction looses session in IIS

I've just run into this issue. Its not related to redirect to action itself but the app pool. What fixed it for me was deleting the app pool the site was running under in IIS and re-creating it. Works fine now. Source

dknaack
  • 60,192
  • 27
  • 155
  • 202
  • Ahh that could be it, i didnt notice it was running off IIS. I will give it a try now. – Matt Seymour Jan 25 '12 at 14:27
  • It is still coming through as null, I am debugging in Visual studio using IIS, this is because there is a classic asp application as part of the code. – Matt Seymour Jan 25 '12 at 14:32
  • @aspect What you mean, "because there is a classic asp application as part of the code" ? – dknaack Jan 25 '12 at 14:35
  • The application is two parts, a classic asp application which runs on one application and a .net MVC3 application which runs on another. For testing purposes I need to be running the code through IIS. – Matt Seymour Jan 25 '12 at 14:37