在 IIS 6.0 的子目录中创建虚拟目录(以编程方式)
我尝试以编程方式在 IIS 6.0 中创建虚拟目录,但在检查虚拟目录是否存在(如果虚拟目录位于嵌套文件夹中)时遇到问题。
因此,如果我有一个文件夹树,例如:
MySite
Folder A (virtual directory)
Folder B
NestedFolder C (virtual directory)
当我获取此站点元数据库的 DirectoryEntry 对象时:
"IIS://<servername>/W3SVC/2/Root"
DirectoryEntry 对象(将称为条目)将有两个子对象,
entry.Children[0].Name = "Folder A"
但entry.Children[1].Name = "Folder B"这不是虚拟目录。我必须执行以下(代码)才能访问嵌套文件夹中的任何虚拟目录:
foreach (var directoryEntry in entry.Children.Cast<DirectoryEntry>().Where(directoryEntry => directoryEntry.SchemaClassName == "IIsWebVirtualDir" || directoryEntry.SchemaClassName == "IIsWebDirectory")) {
foreach (DirectoryEntry child in directoryEntry.Children.Cast<DirectoryEntry>().Where(subChild => subChild.SchemaClassName == "IIsWebVirtualDir")) {
if (child.Name == vDir)
return true;
}
if (directoryEntry.Name != vDir) continue;
return true;
}
这对我来说相当难看。有没有更好的方法可以检查现有虚拟目录(如果它们存在于子文件夹中)?
I am attempting to create virtual directories in IIS 6.0 programmatically and having problems checking if a virtual directory exists if the virtual directory is in a nested folder.
So if I have a folder tree such as:
MySite
Folder A (virtual directory)
Folder B
NestedFolder C (virtual directory)
When I grab the DirectoryEntry object for this site metabase:
"IIS://<servername>/W3SVC/2/Root"
The DirectoryEntry object (will call it entry) will have two children, with
entry.Children[0].Name = "Folder A"
but entry.Children[1].Name = "Folder B" which is not a virtual directory. I have to do the following (code) to get to any virtual directories in nested folders:
foreach (var directoryEntry in entry.Children.Cast<DirectoryEntry>().Where(directoryEntry => directoryEntry.SchemaClassName == "IIsWebVirtualDir" || directoryEntry.SchemaClassName == "IIsWebDirectory")) {
foreach (DirectoryEntry child in directoryEntry.Children.Cast<DirectoryEntry>().Where(subChild => subChild.SchemaClassName == "IIsWebVirtualDir")) {
if (child.Name == vDir)
return true;
}
if (directoryEntry.Name != vDir) continue;
return true;
}
Which to me is quite ugly. Is there a better way that I can check for existing virtual directories if they exist in sub folders?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否正在寻找递归函数来迭代整个站点?
Are you looking for a recursive function to iterate the complete site?