多个ASP.NET配置文件

编程入门 行业动态 更新时间:2024-10-09 23:14:30
本文介绍了多个ASP.NET配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我发现在有一个Web部署多个ASP.NET配置文件的若干条信息。不过,我仍然不确定,如果我能做到我想要完成的任务。

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.

基本上,我工作的网站可以被部署到三个不同的地点。根据其部署到网站上,需要更改的配置设置。我想这样做的是为每个可能的配置配置文件(全web.config文件中),然后可以告诉部署构建用于特定部署该配置文件(我可以编辑该手动如有必要)。

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).

有没有为指向一个不同的config文件一样简单的东西,或者我需要做一些更复杂?

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

编辑:,我有一个特别值得关注的是,我还需要在system邮件设置等设置,因此,我不希望的只有的覆盖的appSettings。

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

感谢

推荐答案

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

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

除了文件= 语句&LT;的appSettings&GT; (这是唯一的应用程序设置可供选择: - ()它不是一个额外的设置 - 你只是你的配置系统指向外部文件

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.

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

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

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

这在 smtp.test.config :

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

本工程为.NET 2.0(甚至1.x中),它适用于每个配置的栏目 - 但不是配置部分群体如&LT;的System.Web方式&gt;

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>.

当然,你现在可以创建额外的配置文件,如 smtp.staging.config 等等,现在你的问题已经降至替换一行你的web.config。

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.

您可以使用安装脚本,一个XML preprocessor,甚至通过人为干预做到这一点。

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

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

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配置文件

本文发布于:2023-11-07 15:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566827.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   配置文件   ASP   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!