在 Server 2008+ 中,我以编程方式在 FTP 站点的虚拟目录 Reports 中创建新文件夹。我可以为每个新文件路径创建一个新的 FTP 授权规则:
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection authorizationSection = config.GetSection("system.ftpServer/security/authorization", "FTP/LDNClient/Reports/aClientPath");
ConfigurationElementCollection authorizationCollection = authorizationSection.GetCollection();
ConfigurationElement addElement = authorizationCollection.CreateElement("add");
addElement["accessType"] = @"Allow";
addElement["users"] = @"LDNClient";
addElement["roles"] = @"";
addElement["permissions"] = @"Read, Write";
authorizationCollection.Add(addElement);
serverManager.CommitChanges();
}
其中“FTP/LDNClient/Reports/aClientPath”是规则的路径。但是对于具有不同路径的同一用户,存在大量元素。如果我打开 applicationHost.config,我可以看到不同的 ConfigurationElements,其路径如下,“aClientPath”:
<location path="FTP/LDNClient/Reports/aClientPath">
<system.ftpServer>
<security>
<authorization>
<remove users="LDNClient" roles="" permissions="Write" />
<add accessType="Allow" users="LDNClient" permissions="Read, Write" />
</authorization>
</security>
</system.ftpServer>
</location>
但是我不知道如何引用该元素,因此我可以(1)删除它或(2)修改权限。我可以通过每个节点滚动:
foreach (ConfigurationElement item in authorizationCollection)
{
// Do something with item here
}
但我可以在“项目”中找到 aClientPath 的路径。使用上面的位置节点,我将如何删除它或修改它的权限?