【问题标题】:Asp.Net MVC 4 App - Sending Request Within iframe Cleared SQL Server SessionAsp.Net MVC 4 App - 在 iframe 清除 SQL Server 会话中发送请求
【发布时间】:2020-04-26 08:12:51
【问题描述】:

我有一个使用自定义会话包装器的 Asp.Net MVC 4 应用程序。会话保存在 SQL 服务器中(SQL Server 模式 - 20 分钟后过期)。典型的客户在 iframe 中打开应用程序,处理他们的订单,并在完成后关闭 iframe。直到最近 IT 安装了最新的 Microsoft 更新时,它一直运行良好。应用程序在 iframe 内发出的所有 ajax 请求都返回 500 错误消息。经过一番调试,我意识到会话对象为空。结果,应用程序抛出了一个空异常。如果我要在 iframe 之外使用该应用程序,它会按预期工作。我一直无法找到解决办法。如果没有解决方法,我将不得不开始添加隐藏标签,以便在请求期间可以使用其中一些值。有人有这个问题的解决方法吗?

会话包装类

[Serializable]
[SessionExpireFilter]
public class SessionWrapper
{
    public static CurrentOrder currentOrder
    {
        get
        {
            if (HttpContext.Current.Session["Order"] != null)
            {
                return (CurrentOrder)HttpContext.Current.Session["Order"];
            }
            else
            {
                return null;
            }
        }
        set
        {
            HttpContext.Current.Session["Order"] = value;
        }
    }
}

在用户开始下单时初始化包装器

CurrentOrder currentOrder= new CurrentOrder();
SessionWrapper.CurrentOrder = currentOrder;

读取或设置会话变量。

SessionWrapper.CurrentOrder.OrderId = anOrderID

if(SessionWrapper.CurrentOrder != null && SessionWrapper.CurrentOrder.OrderId > 0)
   anOrderId = SessionWrapper.CurrentOrder.OrderId

于 2020 年 1 月 9 日更新

经过一些额外的调试,请求不包含会话信息。因此,当 session 不为 null 时的这段代码永远不会执行,因为 session 为 null。

HttpContext.Current.Session["Order"] != null

【问题讨论】:

    标签: asp.net-mvc-4 iframe session-variables session-state


    【解决方案1】:

    终于在this论坛找到了答案。将 'cookieSameSite="None"' 添加到我的 sessionState 标记可以解决问题。

    【讨论】:

      猜你喜欢
      • 2012-03-02
      • 1970-01-01
      • 2015-09-20
      • 2012-10-03
      • 2015-05-18
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多