我正在尝试将一些自定义属性添加到 IIS 中的虚拟目录的配置中,但是当我提交更改时,我得到了 DirectoryNotFoundException
我已经尝试了多种方法,大多数是这样的
var config = serverManager.GetWebConfiguration(serverManager.Sites[0].Name, "mycustomfolder");
var appSettings = config .GetSection("appSettings");
var collection = section.GetCollection();
var elem = conf.CreateElement("add");
elem.SetAttributeValue("key", "createdBy");
elem.SetAttributeValue("value", "me");
serverManager.CommitChanges();
服务器管理器对象明确定义为
using(var serverManager = new ServerManager())
...
我期望在配置中是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
<appSettings>
<clear />
<add key="createdBy" value="me" />
</appSettings>
</configuration>
相反,我收到了一个错误
System.IO.DirectoryNotFoundException: Filename: \\?\C:\inetpub\wwwroot\local\web.config
Error: Cannot write configuration file
at Microsoft.Web.Administration.Interop.IAppHostWritableAdminManager.CommitChanges()
at Microsoft.Web.Administration.ConfigurationManager.CommitChanges()
at Microsoft.Web.Administration.ServerManager.CommitChanges()
按照它尝试保存的路径,我看不到我的虚拟目录的子文件夹,但我可以创建它们,甚至以编程方式