ConfigHelper类用来读取web.config配置的数据

引入 using System.Configuration; 命名空间

public sealed class ConfigHelper

{

   public static string GetConfigString(string key)
  {
            return ConfigurationManager.AppSettings[key];
  }

 

  //可以以扩展得到布尔值

  public static bool GetConfigBool(string key)
  {
   bool result = false;
   string cfgVal = GetConfigString(key);
   if(!String.IsNullOEmpty(cfgVal))
   {
    try
    {
     result = bool.Parse(cfgVal);
    }
    catch(FormatException)
    {
     // Ignore format exceptions.
    }
   }

   return result;
  }

 

}

 

 

相关文章:

  • 2022-02-08
  • 2021-11-20
  • 2021-08-27
  • 2022-02-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-10-05
  • 2021-09-06
  • 2021-05-26
相关资源
相似解决方案