First, let's explain that, after a rough experiment, the class library project and website do not need another solution. As long as the class library referenced by the website can access the connection string in Web. config. P.s is just a simple trial, so there may be errors. I hope you will testify.
In a class library project CodeTo access the connection string in the web. config file that references your website, the class library project must reference system. Web. ProgramAnd then you need to reference the system. Configuration assembly. It is a bit confusing about the latter, which will be discussed later.
Then you can use
System. Web. configuration. webconfigurationmanager. connectionstrings
Access the connection string, just like the code in the website.
Note the following: if the class library is not referenced on the website but is referenced in a project without a configuration file, the preceding statement will not run abnormally, it returns NULL.
Finally. configuration gets worse. connectionstrings is defined in this Assembly, while webconfigurationmanager is defined in system. in web, such a design requires that another assembly be referenced at the same time by using webconfigurationmanager, And the only purpose of referencing that assembly is to access a property of webconfigurationmanager, webconfigurationmanager depends on a specific class defined in other assembly, which obviously violates the interface inversion principle and brings troubles to user calls. It is inexplicable to design.