如何从 APP_CODE 访问 asp.net 会话变量?
我在这里和其他地方看到了很多帖子,指出可以从 app_code 访问会话变量。我想访问一个已经创建的会话。
此代码由于空异常而出错。 字符串 myFile = HttpContext.Current.Session["UploadedFile"];
这会创建一个空会话变量。 System.Web.SessionState.HttpSessionState 会话 = HttpContext.Current.Session;
看起来我可以创建一个新的会话变量,但无法访问已创建的会话变量。有人知道什么可能会给我带来问题吗?
I have seen lots of posts here and elsewhere stating that one can access session variables from app_code. I want to access an already created session.
this code errors out because of a null exception.
string myFile = HttpContext.Current.Session["UploadedFile"];
this creates a null session variable.
System.Web.SessionState.HttpSessionState Session = HttpContext.Current.Session;
It looks like I can create a new session variable but not access an already created one. Anyone have any idea what might be giving me problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,但我能够解决它,因为我控制了事件生命周期中我尝试利用 HttpContect.Current.Session 的位置...这会产生影响,因为 Session 不可用,例如,建造。
也许这会对你有帮助。
I was having ths same problem, but I was able to fix it because I controlled where in the event lifecycle I was attempting to leverage HttpContect.Current.Session... it makes a difference because Session isn't available, for example, on construction.
Maybe that will help you.