访问和删除使用 Ajax 设置的会话
Accesing and removing session that was set with Ajax
我在我的 Web 应用程序上设置了几个使用 ajax 的 sessionStorage.setItem
设置的会话变量
例如
sessionStorage.setItem("id", 345 );
我需要做的是访问、更改并且最重要的是从我的 c# 控制器中删除此类变量
到目前为止我为 removing/destroying 会话变量所做的尝试
Session.RemoveAll();
Session.Remove("id")
Session.Clear();
Session.Abandon();
到目前为止我为访问会话变量所做的尝试
var sesionId = {Controller}.ControllerContext.HttpContext.Session["{id}"];
var sesionId = this.ControllerContext.HttpContext.Session["{id}"];
var sesionId = ControllerContext.HttpContext.Session["{id}"];
//all return null
这些失败的试验取自 Whosebug 中的其他类似问题,但我相信设置变量的方法可能与这些方法对我不起作用的事实有关。
正如 Igor 提到的,我有一个与理论相关的错误,我引用
The two containers are completely different and unrelated - one is in the browser, the other is on the server.
Seems that you are confusing client-side javascript window.sessionStorage and server-side System.Web.HttpContext.Current.Session
由于他的敏锐观察,问题得到了解决
我在我的 Web 应用程序上设置了几个使用 ajax 的 sessionStorage.setItem
例如
sessionStorage.setItem("id", 345 );
我需要做的是访问、更改并且最重要的是从我的 c# 控制器中删除此类变量
到目前为止我为 removing/destroying 会话变量所做的尝试
Session.RemoveAll();
Session.Remove("id")
Session.Clear();
Session.Abandon();
到目前为止我为访问会话变量所做的尝试
var sesionId = {Controller}.ControllerContext.HttpContext.Session["{id}"];
var sesionId = this.ControllerContext.HttpContext.Session["{id}"];
var sesionId = ControllerContext.HttpContext.Session["{id}"];
//all return null
这些失败的试验取自 Whosebug 中的其他类似问题,但我相信设置变量的方法可能与这些方法对我不起作用的事实有关。
正如 Igor 提到的,我有一个与理论相关的错误,我引用
The two containers are completely different and unrelated - one is in the browser, the other is on the server.
Seems that you are confusing client-side javascript window.sessionStorage and server-side System.Web.HttpContext.Current.Session
由于他的敏锐观察,问题得到了解决