Use an Application Wrapper Class to place accessing of all configuration parameters in one place that the whole web application can reference so that you always know where to go to get configuration settings. This will keep developers from wondering where to find all app settings and not to have to do all that is involved with retrieving values from the Web.Config, or for that matter in an app.config file.
The following code is an excerpt from a real ApplicationWrapper Class just to show an example of the whole class. This example is obviously from C#, but you can use ReadOnly Properties in VB.NET just as well. Make sure you have a Reference to the System.Configuration.DLL. Don't you hate it when someone posts code without telling you the refereneces and namespaces needed to make it work? I know I have done it myself, but it is always helpful if example code compiles...
| using System; using System.Collections.Generic; using System.Configuration; using System.Web; |
| public static class ApplicationWrapper { #region public members public static string DBConnection { get { return ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; } } public static int MaxLoginAttempts { get { return int.Parse(ConfigurationManager.AppSettings["MaxLoginAttempts"]); } } public static string Company { get { return ConfigurationManager.AppSettings["Company"]; } } #endregion } |
| Ask a Question, or give your feedback on my articles or products by going to the KnowDotNet Forum or by clicking on My Blog. | ![]() |