2011-09-27 153 views
1

我的.NET MVC3網站正在通過父網站上的iframe加載。他們通過查詢字符串中的某些參數獲取我網站上的控制器操作。我的動作驗證這些參數,將它們存儲在會話中,並執行RedirectToAction()到不同的控制器的操作。在第二個動作中,第一行代碼從會話中獲取這些參數。我們在DEV中沒有任何問題,而且我們在QA中沒有任何問題。IE中的RedirectToAction會話變量丟失

在生產中,重定向之後,會話變量被清除。這隻發生在IE 8和7中。生產服務器確實有一個負載均衡器,但目前第二臺服務器已關閉,問題仍然存在。這裏是代碼,我剝離了驗證和其他一些東西。

//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 :(
} 

非常感謝您提前!

更新:我實現了會話狀態模式「StateServer」。沒有改變。

更新:我正在看小提琴手。 IE:父站點設置會話cookie。我的網站沒有。 FF:這兩個網站都設置了會話cookie。

+0

你是如何存儲在生產服務器會話狀態? inproc,數據庫? – ryudice

+0

我將它存儲爲InProc – Dimskiy

回答

0

加載提琴手。注意Set-Cookie響應並注意cookie域。確保它匹配您的網站。然後在下一個請求(從重定向到動作)確保cookie被髮送,並且再次匹配請求中的域。

+0

我用提琴手信息更新了我的問題。請告訴我是否有任何其他信息可以提供給您。 – Dimskiy

1

另一個可能的原因/解決方案是,IE瀏覽器不會保存cookies,如果域名有下劃線(因爲嚴格地說域名不能有下劃線,所以你可能只遇到這發展),例如http://my_dev_server/DoesntWork。 Chrome或Firefox應該在這種情況下工作,並且如果您更改了您使用的域名,以避免解決下劃線問題。

編號:

+0

說真的,謝謝。這解決了我的問題。幾個小時的排除故障,如果沒有這個答案,我甚至不會考慮這樣的事情。 – Phas1c