我有一个设置了指令EnableSessionState="ReadOnly"的页面。
当我有:
this.Session.Add("MyVar","TempVar");
下一个请求返回NULL。
当我有:
this.Session["MyVar"] = "TempVar";
下一个请求返回“TempVar”
我可以禁用此行为吗?
我有一个设置了指令EnableSessionState="ReadOnly"的页面。
当我有:
this.Session.Add("MyVar","TempVar");
下一个请求返回NULL。
当我有:
this.Session["MyVar"] = "TempVar";
下一个请求返回“TempVar”
我可以禁用此行为吗?
The reason why it does that is because Session[""] is accessing an array using a get;set; accessor that is obviously not set to check for enablesessionstate. So basically its getting put in that array, but its not getting saved. As opposed to the .Add() function which clearly has the check in it. Its probably like that to reduce the overhead on the get;set; properties.
As someone else said you might see it on that same request, but its not getting saved to the session.