在第三方库访问web.config文件 [英] Accessing a web.config file in a third party library

查看:113
本文介绍了在第三方库访问web.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个IHttpFilter这需要在一个单独的项目(这些都是C#项目)的一组ASP.NET MVC应用程序中使用。在IHttpFilter我必须确定在web.config文件中指定的一些东西。

I'm writing an IHttpFilter which needs to be in a seperate project (these are all C# projects) to be used in a set of ASP.NET MVC Applications. In the IHttpFilter I have to determine a few things that are specified in the web.config file.

是否有在运行时从外部程序集检索当前的web.config文件的方法吗?有三种设置,我需要获得(字符串)。

Is there a way of retrieving the current web.config file from an external assembly at runtime? There are three settings that I need to obtain (strings).

另一个问题是,我需要引用一堆文件(图像),但我不知道是否将其放置在ASp.NET MVC应用程序或项目的IHttpHandler

The other problem is that I need to reference a bunch of files (images) but I'm not sure whether to place it in the ASp.NET MVC Application or in the IHttpHandler project.

推荐答案

从外部组件,我明白你的意思是由Web应用程序引用的另一个项目生成的程序集。

From external assembly I understand that you mean an assembly generated by another project referenced by the web application.

在运行时,你的web应用将检索它的整个配置包括那些引用的程序检索 - 从Web应用程序的web.config。你不必在你的IHttpHandler code改变任何东西。

At runtime, your web application will retrieve its entire configuration included those retrieved by referenced assemblies - from the web application's web.config. You don’t have to change anything in you IHttpHandler code.

因此​​,尽管在设计时,你应该对每个项目的配置文件,在运行时这些设置,所有引用的项目配置文件应合并到Web应用程序的web.config文件

So while at design-time you should probably have those settings on each project’s config files, during run-time, all of the referenced projects config files should be merged into the web application’s web.config file.

关于图片:在小试,我在这里所做的,我已经把图片上引用的项目将它们设置为内容,并始终复制到输出目录。虽然大会得到了复制到Web应用程序的bin文件夹如我所料,在图像没有复制到任何地方,除了他们自己的项目输出目录。

About the images: On the small test I’ve done here, I’ve put images on a referenced project setting them as content and to copy always to output directory. While the assembly got copied to the web application’s bin folder as I expected, the images were not copied to anywhere besides their own projects output directory.

所以为了简单起见,我提出的图像在适当的文件夹中的Web应用程序的项目

So for the sake of simplicity, I would put the images at an appropriate folder in the web applications project.

这篇关于在第三方库访问web.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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