Snippet Fire

Beta
 Log In    |   Sign Up

.NET : Set Application Configuration Settings for ASP.NET and ASP.NET MVC

Added on Dec-14-2011 by admin
For .NET

Tags : appsettingsasp-netasp-net-mvcconfigurationmanagerweb.config

Application-wde configuration settings can be placed in the web.config file in the <appSettings> section. These can be read directly using the ConfigurationManager. It may make sense to decouple the ConfigurationManager from the uses of the settings in the app as this will allow you perform additional processing or read/update the settings from a database at a later time without changing the app too much.

DOWNLOAD

<!--web.config snippet-->
<configuration>
  <appSettings>
   <add key="SiteName" value="Snippet Fire" />
  </appSettings>
</configuration>

// In an ASP.NET MVC site this could be placed in the Models folder
// In an ASP.NET site it should be in the app_code folder.

 public static class GlobalSettings
    { 
        public static string SiteName { get {              
        return   ConfigurationManager.AppSettings["SiteName"];   }
    }
}


    

Report Snippet

blog comments powered by Disqus