将我的 Web.Config 应用程序设置存储在单独的文件中时,是否始终需要 IIsreset?

发布于 2024-07-19 04:32:23 字数 318 浏览 13 评论 0原文

我有一个 ASP.Net 应用程序,其中 Web.Config xml 中的 AppSettings 节点存储在单独的文件中。

所以我的 Web.Config 包含以下内容:

<appSettings file="AppSettings.config" />

每当我更改其中的设置时,我都必须执行 iisreset 来强制更改生效。换句话说,我在此文件中的更改不会像对 Web 的更改那样被检测到。配置是.

有谁知道如何让这些更改自动生效,就像 Web.Config 那样?

谢谢!

I've got an ASP.Net app in which my AppSettings node from the Web.Config xml is stored in a separate file.

So my Web.Config contains this:

<appSettings file="AppSettings.config" />

Whenever I change a setting in there I have to do an iisreset to force the changes to kick in. In other words, my changes in this file aren't detected the same way changes to the Web.Config is.

Does anyone know how I can make these changes take effect automatically, like it does with the Web.Config?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

您的好友蓝忘机已上羡 2024-07-26 04:32:23

编辑:回应其他答案。 您可以更改 machine.config 以包含 appSettings 的 restartOnExternalChanges="true" 选项; 但是,当您触摸任何外部应用程序设置文件时,这将导致所有 Web 应用程序重新启动。 (另外,我认为这可能仅在您使用 configSource="file.name" 而不是 file="file.name" 时才有效。)

这是设计使然,导致应用程序重置的唯一方法是手动或通过脚本。

您可以在此处查看一个无需重新启动 iis 即可重置应用程序的脚本:

http://weblogs.asp.net/jgalloway/archive/2006/06/01/Avoid-IISRESET-in-ASP.NET- applications-_2800_added-bonus_3A00_-ASPRESET_2900_.aspx

Edit: In response to other answers. You can change the machine.config to include the restartOnExternalChanges="true" option for appSettings; however, this will cause ALL of your web applications to restart when you touch any of the external app settings files. (Also, I think this may only work when you use configSource="file.name" not file="file.name".)

This is by design and the only way to cause the application to reset is manually or via a script.

You can take a look here for a script which will reset your application without restarting iis:

http://weblogs.asp.net/jgalloway/archive/2006/06/01/Avoid-IISRESET-in-ASP.NET-applications-_2800_added-bonus_3A00_-ASPRESET_2900_.aspx

二货你真萌 2024-07-26 04:32:23

我知道这是一个旧线程,但需要添加一些内容。

如果您使用:

<appSettings file="AppSettings.config" />

则在更改 web.config 或执行重新启动之前,对外部文件的更改将不可用。

但如果您将其更改为:

<appSettings configSource="AppSettings.config" />

对这些设置的更改将立即在您的代码中可用,无需重新启动或 web.config 更改。

我刚刚通过可重复的测试验证了这种情况。

I know this is an old thread, but something to add.

If you use:

<appSettings file="AppSettings.config" />

Then changes to the external file will not be available until a change to web.config is made or a restart is performed.

But if you change that to:

<appSettings configSource="AppSettings.config" />

The changes to those settings are available in your code immediately without a restart or a web.config change.

I just verified that this is the case with a repeatable test.

最美的太阳 2024-07-26 04:32:23

在记事本中打开 web.config。 保存。 退出记事本。

Open web.config in notepad. Save it. Exit notepad.

橙味迷妹 2024-07-26 04:32:23

您如何在代码中访问应用程序设置? 我有一个外部 appsettings 文件(尽管我使用 configSource 属性而不是 file),并且在使用 ConfigurationManager.AppSettings("settingname" 时,我所做的任何更改都会立即可用") 在代码中获取值。

话虽如此,如果您确实因其他原因需要重新启动应用程序,并且您可以访问服务器上的 machine.config 文件,则在 appSettings 部分的定义中,有一个名为 RestartOnExternalChanges 可以设置为 true (默认为 false),然后 appSettings 部分将按照您想要的方式运行,我相信。

How are you accessing your app settings in code? I have an external appsettings file (though i use the configSource property instead of file) and any changes I make are immediately available when using ConfigurationManager.AppSettings("settingname") in code to get the value.

With that said, if you really do need an app restart for some other reason, and you have access to the machine.config file on the server, in the definition for the appSettings section, there is an attribute named RestartOnExternalChanges that can be set to true (defaults to false) and then the appSettings section will behave like you want it to, I believe.

鯉魚旗 2024-07-26 04:32:23

您可以编写 filewatcher 服务来监视您的自定义配置文件。 当更改的事件在服务内执行时发出 iisrest 命令。

You can write a filewatcher service to monitor your custom config file. Issue iisrest command when the changed event gets executed inside the service.

欢你一世 2024-07-26 04:32:23

如果您要改用 ConfigurationRedirection(随 IIS 7 引入),您可以将 IIS 配置为轮询更改外部配置文件(从 IIS 7.5 开始)。 不过,这将覆盖整个 .config 文件,而不仅仅是 appSettings 部分。

这允许您将配置设置存储在网络场中的所有 Web 服务器计算机都可以访问的 UNC 服务器上。

If you were to instead use ConfigurationRedirection (introduced with IIS 7), you could configure IIS to poll for changes to your external configuration file (starting with IIS 7.5). This would cover the whole .config file, though, not just the appSettings section.

This allows you to store configuration settings on a UNC server that all Web server computers in the Web farm can access.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文