如何在ASP.NET中使用C#在运行时更改web.config值时避免IIS或应用程序重新启动? [英] How to avoid IIS or application restart on changing web.config values at run time in ASP.NET with C#?
本文介绍了如何在ASP.NET中使用C#在运行时更改web.config值时避免IIS或应用程序重新启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望在使用c#在asp.net中运行时更改web.config值时避免IIS或应用程序重新启动。我正在根据我的项目范围在运行时更新配置键值。我使用的是IIS 7.5版本。
我尝试了什么:
代码如下:
I want to avoid IIS or application restart on changing web.config values at run time in asp.net with c#. i am updating config key values at run time as per the scope of my project.I am using IIS 7.5 version.
What I have tried:
Code is as below:
WriteTextFile(filename, "Config Value Changing Block Started" + Environment.NewLine);
Configuration objConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings");
//Edit
if (objAppsettings != null)
{
objAppsettings.Settings["application"].Value = "test";
objConfig.Save();
推荐答案
是的,但副作用对我来说是未知的,因为通常不会这样做。
更改外部文件中的配置示例| Microsoft Docs [ ^ ]
您还可以将您的appsettings存储在数据库中,我认为这可能是一个更可行的解决方案。
Yes, but the side effects are unknown to me because this isn't typically done.
Changing Configuration in External File Example | Microsoft Docs[^]
You could also store your appsettings in a database, which I think may be a more viable solution.
>
这篇关于如何在ASP.NET中使用C#在运行时更改web.config值时避免IIS或应用程序重新启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文