asp.net-mvc-4 - Asp.Net MVC 4 App - 在 iframe 清除 SQL Server 会话中发送请求
问题描述
我有一个使用自定义会话包装器的 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
更新于 01/09/2020
经过一些额外的调试后,请求不包含会话信息。因此,当 session 不为 null 时的这段代码永远不会执行,因为 session 为 null。
HttpContext.Current.Session["Order"] != null
解决方案
最后,我在这个论坛找到了答案。将 'cookieSameSite="None"' 添加到我的 sessionState 标记可解决此问题。
推荐阅读
- javascript - 如果单元格 [X] 已写入输入,则从行中获取值
- sqlite - SQLite 的 SUM IFS 等效项
- javascript - 如何显示任何输入数字的最后四位数字,用一串星号掩盖其余数字?
- php - laravel 过滤器仅嵌套条件
- gem5 - 运行完整系统基准测试时的错误函数调用 _m5.event.simulate(*args, **kwargs)
- google-colaboratory - 从 URL 查询参数填写 Colab 笔记本中的表单字段
- python - 在 Python 中读取和使用从 url 请求的图像
- python-3.x - python函数没有返回所需的输出
- c - 非阻塞请求-回复方案 (ZeroMQ)
- python - 我正在获取 Traceback Traceback(最近一次通话最后一次):