您的位置:首页 > 移动开发

得到AppSettings中的配置字符串信息

2015-12-18 14:41 393 查看
得到AppSettings中的配置字符串信息

根据键值对的键key获取对应的值value

/// <summary>
/// 得到AppSettings中的配置字符串信息
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string GetConfigString(string key)
{
string CacheKey = "AppSettings-" + key;
object objModel = DataCache.GetCache(CacheKey);
if (objModel == null)
{
try
{
objModel = ConfigurationManager.AppSettings[key];
if (objModel != null)
{
DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(180), TimeSpan.Zero);
}
}
catch
{ }
}
return objModel.ToString();
}


用法:

string conn=GetConfigString("connection")


注意:需要引用System.Configuration;

using System.Configuration;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: