我有一个页面,其中设置了 EnableSessionState="ReadOnly" 指令。

当我有:

this.Session.Add("MyVar","TempVar");

下一个请求返回 NULL

当我有:
this.Session["MyVar"] = "TempVar";

下一个请求返回 "TempVar"

我可以禁用这种行为吗?

最佳答案

这样做的原因是因为 Session[""] 正在使用 get;set; 访问数组。显然未设置为检查 enablesessionstate 的访问器。所以基本上它被放在那个数组中,但它没有被保存。与 .Add() 函数相反,它显然有检查。它可能是为了减少 get;set; 的开销。特性。

正如其他人所说,您可能会在同一个请求中看到它,但它没有保存到 session 中。

关于c# - 即使 EnableSessionState ="ReadOnly"也设置了 asp.net 变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11316363/

10-13 07:46