Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在运行时编辑configSource文件_C#_Asp.net_Web Config - Fatal编程技术网

C# 在运行时编辑configSource文件

C# 在运行时编辑configSource文件,c#,asp.net,web-config,C#,Asp.net,Web Config,我想在运行时编辑web应用程序的配置,特别是configSource属性引用的文件。每当我尝试使用WebConfiguration Manager打开文件时,我总是得到web.config,而不是rewrite.config 打开后,我想对其进行编辑(例如,清除现有条目,添加新条目)并将其保存回rewrite.config 我是否最好将其作为文件(例如System.IO)读入 web.config rewrite.config 您是否已检查过在运行时使用XPath编辑配置文件?此外,我还看

我想在运行时编辑web应用程序的配置,特别是configSource属性引用的文件。每当我尝试使用WebConfiguration Manager打开文件时,我总是得到web.config,而不是rewrite.config

打开后,我想对其进行编辑(例如,清除现有条目,添加新条目)并将其保存回rewrite.config

我是否最好将其作为文件(例如System.IO)读入

web.config


rewrite.config



您是否已检查过在运行时使用XPath编辑配置文件?此外,我还看到了一些有关StatckoverFlow的示例,这些示例对您有所帮助。。在运行时尝试谷歌搜索
C#Stackoverflow编辑配置文件
我想知道是否可以使用WebConfiguration Manager。XPath与System.IO没有显著差异。有很多关于读取/写入appSettings和连接字符串的教程和问题,但我正在寻找编辑configSource引用的文件中的内容。我倾向于System.IO(或XPath),除非WebConfigurationManager有好处和能力。看看这篇文章,它有一个关于如何使用
WebConfigurationManager
和几行代码的好例子
<system.webServer>
  <rewrite>
    <rules configSource="rewrite.config" />
  </rewrite>
<rules>
  <rule name="rewrite1" stopProcessing="true">
    <match url="^contact-us.html$" />
    <action type="Rewrite" url="/contact-us" />
  </rule>
  <rule name="rewrite2" stopProcessing="true">
    <match url="^about-us.html$" />
    <action type="Rewrite" url="/about-us" />
  </rule>
</rules>