比如我要獲取web.config 裏面的PortalURL
可以直接用
System.Web.Configuration.WebConfigurationManager.AppSettings["PortalURL"].ToString() 獲取。
我寫了一個公用的類,如下參考 :
public class ConfigHelp
{
public static string GetPotalURL()
{
string purl = "http://localhost:80";
try
{
purl = System.Web.Configuration.WebConfigurationManager.AppSettings["PortalURL"].ToString();
}
catch (Exception ex)
{
purl = "http://localhost/error";
}
return purl;
}
}