Read connection string from web.config
问题 How can I read a connection string from a web.config file into a public class contained within a class library? I\'ve tried: WebConfigurationManager ConfigurationManager But these classes are not recognized within my class library. 回答1: Add System.Configuration as a reference. For some bizarre reason it's not included by default. 回答2: You need to add a reference to System.Configuration and then use: System.Configuration.ConfigurationManager. ConnectionStrings["connectionStringName"]