在同一个解决方案C#的另一个项目参考Web.Config文件 [英] Reference Web.Config file from another project in same solution C#

查看:352
本文介绍了在同一个解决方案C#的另一个项目参考Web.Config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VC2010的C#解决方案,拥有一批在IT项目。

I have a VC2010 C# Solution, with a number of projects in it.

因此​​,例如,我有一个web项目,我有一个类库。

So for example, I have a web project, and I have a class library.

在web.config文件中,我在℃的关键;&的appSettings GT; 部分,例如

In the web.config file, I have a key in the <appSettings> section, e.g.

<add key="FileDirectory" value="G:\ftproot\sales" />

我加在Web.Production.config文件密钥,以反映在服务器上的文件的目录。

I have also added a key in the Web.Production.config file to reflect the file directory on the server.

所以,当我引用它在我的web项目(这是MVC) - 我这样做是这样的:

So when I reference it in my web project (It's MVC) - I do so like this:

var FTPPath = ConfigurationManager.AppSettings["FileDirectory"];

这工作正常我的web项目中。但是,我还需要在类库,它得到我的问题引用这个 - 有没有从其他项目,例如引用在web.config文件中的一个关键的方法类库,在同一溶液中??

this works fine within my web project. However, I also need to reference this in the class library, which gets to my question - Is there a way to reference a key in the web.config file from another project, e.g. a class library, in the same solution??

所有帮助AP preciated。
谢谢

All help is appreciated. Thanks

推荐答案

是的,你可以使用完全相同的code。 .NET将查找在启动应用程序域应用程序的配置文件中的配置项。通过这样的应用程序使用的类库将有机会获得它的配置文件。

Yes you can use exactly the same code. .Net will look up the configuration key in the config file of the application which started the app domain. A class library used by such an application will have access to it's config file.

这篇关于在同一个解决方案C#的另一个项目参考Web.Config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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