单个网站目录/多个IIS网站(多个web.config文件) [英] Single Website Directory / Multiple IIS Websites (Multiple web.config files)

查看:521
本文介绍了单个网站目录/多个IIS网站(多个web.config文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一些非常古老的asp代码.因此,我需要解决一个设计问题,如下所述.

I have inherited some very old asp code. I need to resolve a design problem because of it, described below.

我有3个客户... Foo,Bar和Baz.

I have 3 customers... Foo, Bar and Baz.

我有一个名为...的文件夹

I have a folder called...

c:\ WebSites \ Site.v15.07

c:\WebSites\Site.v15.07

我在IIS中有3个网站定义为...

I have 3 websites in IIS defined as...

Website.Foo

Website.Foo

Website.Bar

Website.Bar

网站.巴兹

它们都指向15.07目录.

They all point to the 15.07 directory.

还有3个其他文件夹,称为...

There are 3 other folders called...

c:\ WebConfigurations \ Foo

c:\WebConfigurations\Foo

c:\ WebConfigurations \ Bar

c:\WebConfigurations\Bar

c:\ WebConfigurations \ Baz

c:\WebConfigurations\Baz

...都包含3个站点中每个站点的客户端特定文件.上传的图片等

... which all contain client specific files for each of the 3 sites. Uploaded images etc.

3个客户中的每个客户都有自己的数据库,该数据库位于该网站上.

Each of the 3 customers has their own database that the website sits on.

我需要为3个站点中的每个站点设置(理想情况下,使用web.config)连接字符串.

I need to set (ideally, using a web.config) the connection string for each of the 3 sites.

如果将其放在网站目录根目录下的web.config中,它们将共享相同的设置.

If I put this in the web.config in the root of the website directory, they will all share the same setting.

有没有一种方法可以在IIS的网站"站点上添加设置/web.config.级别,以便可以对每个站点进行不同的设置?

Is there a way of adding the settings/web.config in IIS at the "website" level so that each site can be set differently?

推荐答案

仅将通用配置放在应用程序文件夹的Web.config中.

Put only the common configuration in Web.config in the application folder.

首次加载应用程序时,以编程方式从相应的文件夹加载特定于客户端的配置文件,并以编程方式将信息合并到内存中的配置信息中.

When the application is first loading, programmatically load the client-specific config file from the respective folder and programmatically merge the info into the configuration info in memory.

以编程方式在内存中编辑配置信息的示例:

Example of programmatically editing configuration info in memory:

使用C#(.NET )

var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
section.ConnectionStrings["MyConnectionString"].ConnectionString = "Data Source=...";

在您的情况下,您需要两次调用WebConfigurationManager.OpenWebConfiguration,一次调用打开应用程序配置,一次调用加载客户端配置.然后将数据从客户端配置复制到内存应用程序配置中(不要根据所引用的问题调用Save(),这是不同的用例).

In your case you'll want to make two calls to WebConfigurationManager.OpenWebConfiguration, one to open the application config and once to load the client configuration. Then copy data from client config to the in-memory application config (don't call Save() per the referenced question--that's a different use case).

这篇关于单个网站目录/多个IIS网站(多个web.config文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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