关于ASP.NET的web.config的小笔记
在ASP和MVC開發(fā)中,有一些參數(shù)是需要活動(dòng)更改的,最常見的就是數(shù)據(jù)庫的鏈接字符串<connectionStrings>節(jié)點(diǎn)下配置的。在今天接觸的項(xiàng)目中,我又接觸到了自定義配置參數(shù),就是可以根據(jù)項(xiàng)目需要在web.config中自己定義需要的參數(shù)值。
具體方法:
在<configuration></configuration>節(jié)點(diǎn)下新增<appSettings></appSettings>節(jié)點(diǎn)。
然后在這個(gè)節(jié)點(diǎn)下就可以自定義配置參數(shù):<add key="KEY" value="VALUE" />
使用方法:
ConfigurationManager.AppSettings["Key"]獲取web.config中對(duì)應(yīng)值。
注意:使用ConfigurationManager時(shí)需引用命名空間System.Collections.Generic;
web.config配置文件示例:
?
<configuration><appSettings><add key="APPID" value="wx116a17a17689178c"/><add key="APPURL" value="http://miragefirefox.imwork.net/Home/RedirectLogin"/></appSettings> </configuration>?
使用自定義配置示例:
public static string Appid
{
get
{
return ConfigurationManager.AppSettings["APPID"];
}
}
public static string AppUrl
{
get
{
return ConfigurationManager.AppSettings["APPURL"];
}
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/MirageFox/p/4814070.html
總結(jié)
以上是生活随笔為你收集整理的关于ASP.NET的web.config的小笔记的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 测试你的Python 水平----7
- 下一篇: asp.net ajax控件工具集 Au