Accessing the web.config from a DLL

Sometimes your website (or a site someone else made)  will include a DLL that interface with your site.  In a recent project, I encountered an issue where the DLL needed to utilize the web.config to access the database. With a quick search, I encountered many others with the same problem. There was a few solutions, but none of them work out of the box. With a little tweaking I was able to make it work. In the web.config we have our connectionString: <connectionStrings> MyDBConnection” connectionString =”server=localhost;database=MyDB; user id=username; pwd=password”/> </connectionStrings> And to access it from the DLL: string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings[“MyDBConnection”].ToString(); Continue reading