【问题标题】:Session cookie issues between environments环境之间的会话 cookie 问题
【发布时间】:2017-04-16 20:36:55
【问题描述】:

我在两台机器之间遇到了一个奇怪的问题。两台机器都是带有 Internet Explorer 11 的 Window 7 SP1。我正在使用 MVC4 和 Visual Studio 2013 和 Selenium Web Driver 来做我的 Web UI 测试。

运行我的 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 在发布到登录控制器时似乎总是为空。

【问题讨论】:

  • 我已经读过,但并没有解决它:(
  • @LmC 那个帖子里有各种解决方案,你真的都试过了吗?
  • 有但是还是没解决,好奇怪

标签: c# asp.net-mvc session cookies selenium-webdriver


【解决方案1】:

在我的测试机器中我必须使用

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

允许测试运行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 2014-03-04
    • 2020-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多