如何以编程方式覆盖web.config设置 [英] How to programmatically override web.config settings

查看:112
本文介绍了如何以编程方式覆盖web.config设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在web.config中特定设置,说会话状态的配置,我想以编程方式确定的Application_Start配置,我将如何去了解这一点。我想有每一个环境配置稍有不同。

When I have a specific setting in web.config, say the session state configuration, and I want to programmatically determine the configuration at Application_Start, how would I go about this. I am trying to have a slightly different configuration per environment.


  • 我不希望覆盖真实的web.config(prevent重启)

  • 我知道解决的办法presented在<一个href=\"http://stackoverflow.com/questions/480538/use-xml-includes-or-config-references-in-app-config-to-include-other-config-files\">http://stackoverflow.com/questions/480538/use-xml-includes-or-config-references-in-app-config-to-include-other-config-files,但我不希望在一个单独的文件中,整个的System.Web部分,Sys​​tem.Web程序不实现象的appSettings和做是connectionStrings文件属性。

  • I do not want to overwrite the real web.config (prevent restarts)
  • I know the solution presented in http://stackoverflow.com/questions/480538/use-xml-includes-or-config-references-in-app-config-to-include-other-config-files, but I don't want the whole system.web section in a separate file, and system.web does not implement a file attribute like appSettings and connectionStrings do.

任何想法?

推荐答案

我不认为你可以改变在运行时从web.config设置没有它重新加载应用程序。正如@ ChristopheD的回答显示了文章,你可以阅读和运行时写的web.config设置,但是当它写出的变化为他们节省重新启动应用程序。我是pretty相信,一旦你的应用程序获得的地步,你可以这样做ASP.NET已经在阅读,并在运行时更改他们不保存就不会有任何效果。

I don't think that you can alter settings from the web.config at runtime without it reloading the application. As the article in @ChristopheD's answer shows, you can read and write web.config settings at runtime, but saving them restarts the application when it writes out the changes. I'm pretty sure that once your app gets to the point where you can do this ASP.NET has already read them in and changing them at runtime without saving them will have no effect.

FWIW,我建议对在运行这种类型的环境特定的操纵。更好的办法是在构建或部署的时间来改变每个环境中的web.config。 MSDeploy有办法做到这一点,该功能即将VS2010。

FWIW, I'd recommend against this type of environment-specific manipulation at runtime. A better approach is to alter the web.config per environment at build or deployment time. MSDeploy has a way to do this, and that functionality is coming to VS2010.

这篇关于如何以编程方式覆盖web.config设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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