asp.net - 如何在asp.net中声明变量
问题描述
我有一个字符串变量,我在所有页面中都使用了该变量。所以我决定我们声明一个类,并将字符串设置为公共的。在我在一个地方为该变量赋值之后。我在另一个页面中检索字符串变量的值没有出现。所以我需要如何使用公共变量。
Public Class Class1
Shared _importantData As String
Public Shared Property ImportantData As String
Get
Return _importantData
End Get
Set(ByVal value As String)
_importantData = value
End Set
End Property
End Class
在登录页面中,我将值分配给公共变量
Class1.ImportantData = "Data Source=" +
ConfigurationManager.AppSettings("DataSource").ToString +
";Initial Catalog=" +
ConfigurationManager.AppSettings("InitialCatalog").ToString +
";User ID=" + Session("username") + ";Password=" +
ConfigurationManager.AppSettings("Password").ToString + ""
在第二页我检索这样的值
Dim comsd As String = Class1.ImportantData
解决方案
推荐阅读
- python - 调用 super().__init__(**kwargs) 和多重继承?
- mysql - 如何创建mysql函数
- c - C中的猜谜游戏,无法获得尝试工作的次数,变量是“计数器”
- node.js - 使用node js创建webrtc视频、语音通话和文件传输一步一步QA
- java - 触发多个线程获取数据时查询无法得到结果
- vba - 通过vba提取html文本
- java - Spring Boot 应用程序如何在 JSONformate 中发送多个响应
- r - R中的“指定的时间序列参数无效”错误
- android - 通过谷歌助手打开特定的应用程序屏幕(如深层链接)
- android - 在模拟器中安装应用程序时出现“无 Internet 连接”