我有一个使用自定义会话包装器的Asp.Net MVC 4应用程序。会话将保存在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年09年09日
经过一些额外的调试后,请求不包括会话信息。因此,当会话为null时,代码段将不会执行,因为会话为null。
HttpContext.Current.Session["Order"] != null
发布于 2020-01-10 18:31:32
最后,我在这论坛上找到了答案。在我的cookieSameSite=标记中添加‘sessionState“”None“可以解决这个问题。
https://stackoverflow.com/questions/59651836
复制相似问题