多个ASP.NET配置文件 [英] Multiple ASP.NET Configuration Files

查看:127
本文介绍了多个ASP.NET配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发现了许多关于为Web部署设置多个ASP.NET配置文件的信息。但是,我仍然不确定是否可以完成我想要完成的工作。



基本上,我正在开展的网站可以部署到三个不同的网站。根据部署的站点,需要更改配置设置。我想做的是为每个可能的配置(完整的web.config文件)配置文件,然后能够告诉部署构建哪个配置文件用于特定部署(如果需要,我可以手动编辑)。 / p>

有没有什么简单的指向不同的.config文件,还是需要做更复杂的事情?



编辑:我特别关注的是我还需要在system.net中设置邮件设置等等。所以,我不是只想 覆盖appSettings。



谢谢

解决方案

任何配置部分 - 作为< smtp> - 可以外化,例如存储在外部文件中。



除了 file = 声明< appSettings> (仅适用于应用设置:-()它不是附加设置 - 您只需将配置系统指向外部文件。



所以你可以在你的app.config / web.config中有这个:

 < system.net> 
< mailSettings> ;
< smtp configSource =smtp.test.config/>
< / mailSettings>
< /system.net>

,并在您的 smtp.test.config

 <?xml version =1.0encoding =utf-8?> 
< smtp>
< host =smtp.test.comport =244userName =testpassword =secret/>
< specifiedPickupDirectory pickupDirectoryLocation =C:\temp\mails/>
< / smtp>

这个工作与.NET 2.0(甚至是1.x ),它适用于每个配置部分 - 但不适用于部分组,例如< system.web>



当然,您现在可以创建其他配置文件,例如 smtp.staging.config 等等,现在您的问题已经减少到替换您的web.config中的单行。



您可以使用安装脚本,XML预处理器,甚至通过人为干预执行此操作。



它不能完全解决问题,因为 .NET 4和web.config转换希望会,但这是一个步骤和一点帮助。


I have found a number of pieces of information on having multiple ASP.NET configuration files for a web deployment. However, I am still unsure if I can accomplish what I want to accomplish.

Basically, the website I am working on can be deployed to three different sites. Depending on the site that it is deployed to, the configuration settings need to be changed. What I would like to do is have configuration files for each possible configuration (full web.config files) and then be able to tell a deployment build which config file to use for a particular deployment (I can edit this manually if necessary).

Is there something as simple as pointing to a different .config file, or do I need to do something more sophisticated?

EDIT: One particular concern that I have is that I also need settings in system.net for mail settings, etc. So, I'm not looking to only override the appSettings.

Thanks

解决方案

Any configuration section - such as <smtp> - can be "externalized", e.g. stored in an external file.

Other than the file= statement on <appSettings> (which is available only for app settings :-() it's not a "additional" setting - you just point your config system to an external file.

So you could have this in your app.config/web.config:

  <system.net>
    <mailSettings>
      <smtp configSource="smtp.test.config" />
    </mailSettings>
  </system.net>

and this in your smtp.test.config:

<?xml version="1.0" encoding="utf-8" ?>
<smtp>
  <network host="smtp.test.com" port="244" userName="test" password="secret" />
  <specifiedPickupDirectory pickupDirectoryLocation="C:\temp\mails"/>
</smtp>

This works as of .NET 2.0 (maybe even 1.x), and it works for every configuration section - but not for configuration section groups like <system.web>.

Of course, you can now create additional config files, like smtp.staging.config and so forth, and now your problem has been reduced to replacing a single line in your web.config.

You can do this using an installation script, a XML preprocessor, or even by human intervention.

It doesn't completely solve the problem as .NET 4 and the web.config transformations hopefully will, but it's a step and a bit of help.

这篇关于多个ASP.NET配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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