I want to create a variable in web.config file and to use that variable in web forms. How can I achieve this??
我想在web中创建一个变量。配置文件并在web表单中使用该变量。我怎样才能做到这一点呢?
3 个解决方案
#1
58
in web.config:
在web . config:
<appSettings>
<add key="message" value="Hello, World!" />
</appSettings>
in cs:
在cs:
string str = ConfigurationManager.AppSettings["message"].ToString();
#2
13
You may try like this:
你可以这样试试:
<appSettings>
<add key="id" value="12762"/>
<add key ="url" value="http://localhost:10982/Redirect.aspx"/>
</appSettings>
Then you can use
然后您可以使用
using System.Configuration;
and use it like this:
像这样使用它:
string id=ConfigurationManager.AppSettings["Id"].ToString();
string url=ConfigurationManager.AppSettings["Url"].ToString();
#3
4
FYI: The accepted answers for accessing web.config data are considered "Obsolete" now and should be replaced with:
供参考:访问web的公认答案。配置数据现在被认为是“过时的”,应该替换为:
Example:
例子:
in web.config:
在web . config:
<appSettings>
<add key="message" value="Hello, World!" />
</appSettings>
in c#:
在c#中:
ConfigurationManager.AppSettings["message"]
Reference: ConfigurationSettings.AppSettings is obsolete, warning
参考:ConfigurationSettings。AppSettings已经过时了,警告
#1
58
in web.config:
在web . config:
<appSettings>
<add key="message" value="Hello, World!" />
</appSettings>
in cs:
在cs:
string str = ConfigurationManager.AppSettings["message"].ToString();
#2
13
You may try like this:
你可以这样试试:
<appSettings>
<add key="id" value="12762"/>
<add key ="url" value="http://localhost:10982/Redirect.aspx"/>
</appSettings>
Then you can use
然后您可以使用
using System.Configuration;
and use it like this:
像这样使用它:
string id=ConfigurationManager.AppSettings["Id"].ToString();
string url=ConfigurationManager.AppSettings["Url"].ToString();
#3
4
FYI: The accepted answers for accessing web.config data are considered "Obsolete" now and should be replaced with:
供参考:访问web的公认答案。配置数据现在被认为是“过时的”,应该替换为:
Example:
例子:
in web.config:
在web . config:
<appSettings>
<add key="message" value="Hello, World!" />
</appSettings>
in c#:
在c#中:
ConfigurationManager.AppSettings["message"]
Reference: ConfigurationSettings.AppSettings is obsolete, warning
参考:ConfigurationSettings。AppSettings已经过时了,警告