Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
尝试使用应用程序状态创建和读取全局变量。
在 default.aspx 我在 Page_Load 中有这一行
Application("myValue") = "theValue"
在类 Bomb 中(放置在 App_Code 目录中),我尝试检索值
Dim s As String = Application("myValue")
但在这里我收到一条错误消息,说“应用程序未声明。由于其保护级别,它可能无法访问”
我哪里出错了?
您需要获取应用程序的当前上下文,或者传入上下文。
例如:
Dim s As String = HttpContext.Current.Application("myValue").ToString()