单一登录,iframe,会话无效

时间:2019-04-08 12:37:15

标签: c#

Am正在处理单一登录应用程序,该应用程序正在登录到Windows 2012 Server中托管的框架版本为4.5的一个应用程序,在URL中传递了访问令牌,然后使用IFrame,试图将数据发布到我的mvc应用程序中Windows 2016服务器中托管的.net core 2.0。

通过iframe验证访问令牌,该框架还在本地设置会话数据,然后在页面生命周期内使用该会话。

在我的authcontroller中验证请求之后,我有了RedirectToAction方法,这使我的会话为空。请任何人帮忙

- 我的iframe网址-http://ipaddress/Auth/VaildateToken?ssoToken=4234dfgdfg

正在验证令牌并设置会话的MVC应用程序。

 public IActionResult VaildateToken(string ssoToken)
    {
        var result = _Service.VaildateAccessToken(ssoToken);
        if (result != null)
        {                             
            SetSession(result);                    
            return RedirectToAction("Index", "Controller");                           
        }
        else
        {
            return RedirectToAction("NoAccess");
        }
    }

 public void SetSession(Client client)
    {          
        HttpContext.Session.SetString("EmailId", client.EmailId.ToString());        

        HttpContext.Session.SetString("UserName", client.UserName.ToString());           
    }

会话设置良好,但在再次检查会话时将其重定向到Action结果后,则为空。

    public IActionResult Index()
    {
        string EmailId = HttpContext.Session.GetString("EmailId");
        if (string.IsNullOrEmpty(EmailId))
        {
            return RedirectToAction("logout", "Login");
        }
    }

,然后我在iframe中看到一个登录页面。您能帮忙吗?我怀疑这可能是由于重定向到操作所致,还是缺少在iframe中设置会话的原因。

感谢您的帮助。谢谢

1 个答案:

答案 0 :(得分:0)

这两个站点托管在2个不同的OS版本中。一个在Windows Server 2012中,另一个在Windows 2016中。发布到较高版本的OS时,较低版本不支持会话。

在将两个站点托管在相同的OS版本中时,代码可以正常工作。

相关问题