Skip to content

Instantly share code, notes, and snippets.

@ljinke
Created September 5, 2013 03:33
Show Gist options
  • Save ljinke/6445760 to your computer and use it in GitHub Desktop.
Save ljinke/6445760 to your computer and use it in GitHub Desktop.
/// <summary>
/// Used for configuration when different user use different settings e.g. db connection string
/// </summary>
public static class ConfigurationUtil
{
static NameValueCollection appSettings = ConfigurationManager.AppSettings;
static ConnectionStringSettingsCollection connectionStrings = ConfigurationManager.ConnectionStrings;
public static string GetAppSetting(string name)
{
string tmpName = string.Format(@"{0}\{1}", System.Environment.MachineName, name);
string tmpValue = appSettings[tmpName];
if(string.IsNullOrEmpty(tmpValue))
{
tmpValue = appSettings[name];
}
return tmpValue;
}
public static string GetConnectionStrings(string name)
{
string tmpName = string.Format(@"{0}\{1}", System.Environment.MachineName, name);
var tmpValue = connectionStrings[tmpName];
if (tmpValue==null)
{
tmpValue = connectionStrings[name];
}
return tmpValue.ConnectionString;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment