如何从引用的程序集访问Web.config?

Mar*_*olo 1 asp.net assemblies web-config

我需要从引用的程序集访问Web应用程序的web.config.我需要获取文件的路径或配置对象.我不能像使用System.Reflection.Assembly.GetEntryAssembly那样为应用程序配置windows exe.

谢谢

M4N*_*M4N 7

我在我的类库中使用以下代码从配置文件中读取:

using System.Configuration;

...

string value = ConfigurationManager.AppSettings.Get("myKey");
// returns null if the specified key does not exist
Run Code Online (Sandbox Code Playgroud)

这适用于读取Web应用程序(web.config)和Windows窗体/控制台应用程序(application.exe.config)中的应用程序设置.