我有一个使用类库dll的Web应用程序.我无法访问类库中的app.config值.如何访问app.config ... [英] I have a web application which is using a dll of a class library . I am unable to access the app.config value in the class library How to access app.config ...

查看:62
本文介绍了我有一个使用类库dll的Web应用程序.我无法访问类库中的app.config值.如何访问app.config ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用类库dll的Web应用程序.我无法访问类库中的app.config值

如何访问app.config

I have a web application which is using a dll of a class library . I am unable to access the app.config value in the class library

How to access app.config

ConfigurationSettings.AppSettings["conStr"].ToString();

--->这将返回空值
另外,当我尝试使用ConfigurationManager时,它说未找到或缺少程序集引用.

还添加了

---> this is returning null value
Also when i try to use ConfigurationManager it says not found or missing assembly reference.

using System.Configuration

.

推荐答案

如果它是Web应用程序,则需要将密钥放在web.config(位于AppSettings下)节点中.
Web应用程序中使用的所有类库都将有权访问web.config密钥.

对于ConfigurationManager,您将需要手动添加引用,还需要添加名称空间
If it is a web application, then you need to put the key in the web.config (under AppSettings) node.
All the class libraries used in web application will have access to web.config keys.

For ConfigurationManager, you will need to add a reference manually and also add a namespace
using System.Configuration;



希望对您有帮助
Milind



Hope that helps
Milind


您必须将AppSettings值放入应用程序的web.config中,因为它会覆盖类库中的app.config.

在类库项目中添加对System.Configuration命名空间的引用,它们从web.config文件而不是app.config文件中获得所需的值.
You must put the AppSettings value inside the web.config of the application, because it override the app.config from the class library.

Add a reference to System.Configuration namespace in the class library project, them get the value you''re expecting from the web.config file, not from the app.config file.


这篇关于我有一个使用类库dll的Web应用程序.我无法访问类库中的app.config值.如何访问app.config ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆