【问题标题】:WebMatrix Session variables not workingWebMatrix 会话变量不起作用
【发布时间】:2012-10-17 18:39:05
【问题描述】:

由于我的疏忽(对于 AppState 和 Session 变量仍然是新手),我必须将我的所有 AppStates 更改为 Session 变量。 WebMatrix 的替换使这部分变得简单,但是我现在在下面两行代码的第一行中遇到了这个错误:

Session["gActionMessage"] = "";
Session["gActionMessageDisplayed"] = "not";

错误:

Compiler Error Message: CS0103: The name 'Session' does not exist in the current context

如果重要,这些代码行在我的 _AppStart.cshtml 文件中。

有什么建议吗?是不是语法错了?

【问题讨论】:

    标签: c# session-variables webmatrix


    【解决方案1】:

    在执行 _AppStart.cshtml 文件时会话不可用。这在管道中发生得太早了。您可以使用 _PageStart.cshtml 来初始化会话变量。

    【讨论】:

    • 是的,我终于在昨晚的研究中看到了这一点。我无法相信找到它有多难。我在 mikesdotnetting(Mike Brind 的网站)上找到了它。我不得不搜索我的怀疑,即 Session 变量不能完全在 _AppStart 中启动。感谢您的验证,先生,他们现在工作得很好!
    • Mike Brind 的网站:mikesdotnetting.com/Article/192/…
    猜你喜欢
    • 1970-01-01
    • 2013-11-10
    • 2015-09-30
    • 2013-04-12
    • 2012-08-17
    • 2014-05-16
    相关资源
    最近更新 更多