2014-02-18 48 views
0

我在兩臺機器之間遇到了一個奇怪的問題。這兩臺機器都是帶有Internet Explorer 11的Window 7 SP1。我正在使用MVC4與Visual Studio 2013和Selenium Web Driver來完成我的Web UI測試。環境之間的會話cookie問題

當運行我的UI測試的開始時,每個測試都必須登錄到系統。在我的控制器代碼我有一個使用下面的代碼的方法:

private const string CurrentUserSessionKey = "CurrentUser"; 
private ICache _cache; 

public virtual User User 
{ 
    get 
    { 
     User invokingUser = null; 
     if (HttpContext.Current.Session[CurrentUserSessionKey] != null) 
     { 
      invokingUser = HttpContext.Current.Session[CurrentUserSessionKey] as User; 
     } 
     return invokingUser; 
    } 
    set 
    { 
     HttpContext.Current.Session[CurrentUserSessionKey] = value; 
    } 
} 

奇怪的是您發出它的工作原理內開發環境,而不是由測試環境

在我的開發環境中,它記錄了用戶的情況。在我的生產環境中,HttpContext.Current.Session在發佈到登錄控制器時總是顯示爲空。

+0

http://stackoverflow.com/questions/218057/httpcontext-current-session-is-null-當我路由請求 – pravprab

+0

我讀過,並沒有解決它:( – LmC

+0

@ LMc有在該線程中的各種解決方案,你真的嘗試了所有? – Arran

回答

0

在我的測試機器我必須使用

<sessionState mode="InProc" timeout="20" cookieless="AutoDetect" /> 
Look here for more info on the SessionState directive. 

爲了讓測試運行