How to use ConfigurationManager Class in a Class Library Project type

Akil Vhora picture Akil Vhora · Nov 5, 2011 · Viewed 20.5k times · Source

I have one class Library Project for Payment. The live credential of client is on web.config file of website and this class library project will added in bin in form of dll. So How to get ConfigurationManager in Class Library So I can get credential of Client and make Payment

Answer

Muhammad Hasan Khan picture Muhammad Hasan Khan · Nov 5, 2011

Generally a class in the library shouldn't be reading web.config directly and take settings in constructor.

However it is acceptable for library in some scenarios to read the web.config directly. For that you can define a custom configuration section or use WebConfigurationManager.AppSettings

You need to add reference to System.Web assembly and you need to include the namespace System.Web.Configuration in the file where you want to use configuration manager.