Reputation: 749
So I have a Solution with 1 Class Library and 1 MVC project. The MVC project references the Class Library. I created a ConnectionString class in the Class library that looks like this:
public static string MyAppConnectionString { get; set; } =
ConfigurationManager.ConnectionStrings["MyApp"].ConnectionString;
Everything is working fine. But what I don't understand is how ConfigurationManager.ConnectionStrings knows about the ConnectionStrings of BOTH the app.config file of the Class library AND the Web.Config file of the MVC project?
Upvotes: 0
Views: 2610
Reputation: 960
The web.config file of the MVC app will be considered for ConfigurationManager and so your connection string has to be inside it.
Upvotes: 0
Reputation: 2562
ConfigurationManager works against the app.config file of the currently running executable, or in the case of web applications, against the web.config file. It does not use the app.config found in your library project.
Upvotes: 2