1

My .NET MVC3 website is being loaded through an iframe on the parent website. They GET a controller's action on my website with certain parameters in the query string. My action validates these parameters, stores them in session and does RedirectToAction() to a different controller's action. In the second action, the first line of code gets these parameters from session. We did not have any problems in DEV, moreover we did not have any problems in QA.

In Production, after the redirect, the session variable gets cleared. This only happens in IE 8 and 7. The Production server does have a load balancer, but at the moment the second server is turned off and the problem is still there. Here is the code, I stripped out validation and some other stuff.

//Here is where they come in
[HttpGet]
public ActionResult Index(string locationGUID, string OtherParam)
{
   //?locationGUID=ABCDEFGHIJKLMNOP,XXXXXXXXX&ContractInstance=2111,#####
   //some validation here
    
   var passedData = new PassedData
       {
         Guids = locationGUID.Split(',').ToList(),
         OtherParam = OtherParam 
       };
    
    
   PassedData = passedData;
    
   //more validation and init DB logging here
    
   return RedirectToAction("Index", "OtherController");
}
    
//PassedData is a property of Base Controller, from which all other controllers inherit
public PassedData PassedData
{
   get { return (PassedData)Session["PassedData"]; }
   set { Session["PassedData"] = value; }
}
    
//Here is Index of "OtherController", when we get here in Prod in IE, first line throws null reference exception, because PassedData is now NULL....
[HttpGet]
public ActionResult Index()
{
   ViewBag.CustInfoList = PassedData.Guids.Select(guid => GetCustomerInfo(guid).Data).ToList();
//the rest of the code is not relevant to this question, since PassedData is already NULL :(
}

Update

I implemented session state mode "StateServer". Nothing changed.

Update

I'm looking at Fiddler. IE: The parent site sets session cookie. My site doesn't. FF: Both sites set session cookie.

halfer
  • 19,824
  • 17
  • 99
  • 186
Dimskiy
  • 5,233
  • 13
  • 47
  • 66

3 Answers3

3

This is due to IE not trusting cookies created by IFrames

See Cookie blocked/not saved in IFRAME in Internet Explorer for a detailed explanation and a fix.

HTH

Community
  • 1
  • 1
unclepaul84
  • 1,404
  • 8
  • 15
1

Another possible cause/solution is that IE doesn't save cookies if the domain name has an underscore (because strictly speaking domain names can't have underscores, so you'll probably only encounter this in development), e.g. http://my_dev_server/DoesntWork. Chrome or Firefox should work in this scenario, and if you change the domain name you're using to not have an underscore problem solved.

Ref:

Rory
  • 40,559
  • 52
  • 175
  • 261
  • Seriously, thank you. This resolved my issue. Hours of troubleshooting and I still wouldn't have even considered something like this without this answer. – Mattiavelli Sep 17 '15 at 15:14
0

Load up fiddler. Watch for the Set-Cookie respond and note the cookie domain. Ensure it matches your site. Then on the next request (from redirect to action) ensure the cookie is sent over, and again, it matches the domain in the request.

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • I updated my question with fiddler info. Please, let me know if there is any other information I could provide you with. – Dimskiy Sep 27 '11 at 19:15